xsd - XML Schema force two attributes to be different -


in xml have defined categories

<category id="3" parent-category-id="2">     <name>child category</name> </category> 

as can see have category element, can have parent category defined. both attributes defined in xml schema file:

<xs:attribute name="id" use="required" type="xs:string" /> <xs:attribute name="parent-category-id" use="optional" type="xs:string" /> 

i have keys , keyrefs set in xsd file. wonder if possible somehow restrict parent-category-id, cannot point self id. example can write:

<category id="3" parent-category-id="3"> 

and such xml file still validate, althought shouldn't.

my keys , keyrefs are:

<xs:key name="id">     <xs:selector xpath="categories/category" />     <xs:field xpath="@id" /> </xs:key>  <xs:keyref name="parent_category_id_ref" refer="id">     <xs:selector xpath="categories/category" />     <xs:field xpath="@parent-category-id" /> </xs:keyref> 

it great, if add kind of restriction, tell validator id cannot == parent-category-id. ideas?

if have xsd validator supports version 1.1, can use assert after xs:attribute elements enforce restriction:

<xs:assert test="@id != @parent-category-id"/> 

personally i'm having trouble locating validator support 1.1 though. version 1.0 not support assert.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -