Can we have some rule in XSD which says: All those elements having ID as its attribute should treat it as unique ID so that other elements should not use that ID. How to apply that as getElementById("id") works only after that.
Thanks
Can we have some rule in XSD which says: All those elements having ID as its attribute should treat it as unique ID so that other elements should not use that ID. How to apply that as getElementById("id") works only after that.
Thanks
If you have only digits for your identifier, you can't use xs:id. Then here is a sample schema :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="root" type="rootType">
<xs:key name="attritemIdentifier">
<xs:selector xpath="item"/>
<xs:field xpath="@XYZ"/>
</xs:key>
</xs:element>
<xs:complexType name="rootType">
<xs:sequence>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="XYZ" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
And here is a valid instance :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item XYZ="12345">item0</item>
<item XYZ="XYZ1">item1</item>
<item XYZ="XYZ2">item2</item>
<item XYZ="XYZ3">item3</item>
<item XYZ="XYZ4">item4</item>
<item XYZ="XYZ5">item5</item>
<item XYZ="XYZ9">item6</item>
<item XYZ="XYZ7">item7</item>
</root>
As soon as you have to attribute XYZ with the same value, you'll get the following error :
cvc-identity-constraint.4.2.2: Duplicate key value [XYZ9] declared for identity constraint "attritemIdentifier" of element "root"