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
Post a Comment