xml - How to check that attributes are unique with RelaxNG? -


with relaxng, can check whether or not value of attribute unique within enclosing element?

for example, castle should validate:

<castle>   <room>     <door to="north" />     <door to="south" />   </room>   <room>     <door to="north" />   </room> </castle> 

but should not (duplicate door in same room):

<castle>   <room>     <door to="dungeon" />     <door to="dungeon" />   </room> </castle> 

i'm using relaxng (compact). don't know attribute values 'ahead of time', should unique within room.

thanks!

to knowledge can't done in pure relax ng. use (embedded) schematron, did citation style language schema. if take route, note not relax ng validators parse embedded schematron, , support standalone schematron schemas limited. e.g. popular jing xml validator supports older schematron 1.5 version, not newer iso schematron.

for our project, use jing, use script first convert our relax ng compact schema relax ng xml format (with trang), extract schematron rules relax ng xml schema standalone schematron schema (with saxon , rng2schtrn.xsl xslt style sheet), , validate against extracted schematron schema jing.

if hasn't scared off, cobbled following schematron 1.5 schema problem:

<?xml version="1.0" encoding="utf-8"?> <sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">   <sch:pattern name="duplicateattributevalues">     <sch:rule context="//room/door[@to]">       <sch:report test="preceding-sibling::door/@to = @to">warning: @to values should unique given room.</sch:report>     </sch:rule>   </sch:pattern> </sch:schema> 

when run on following xml document,

<?xml version="1.0" encoding="utf-8"?> <castle>   <room>     <door to="north"/>     <door to="south"/>     <door to="west"/>   </room>   <room>     <door to="west"/>     <door to="north"/>     <door to="west"/>   </room> </castle> 

jing report

error: warning: @to values should unique given room.
line 11, column 5; line 11, column 21
th"/>↩ <door to="west"/>↩ </r


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -