Asserting element Id uniqueness globally with XML 1.1 schema

danelson

New Member
Is it possible to use XML 1.1 schema to verify that that no two elements in a document share an id. For example, the attached XML document should fail because the id's 0, 1 and 3 are not unique.\[code\]<?xml version="1.0" encoding="UTF-8"?><Item> <c id="0"/> <!-- error: shared id --> <a id="1"/> <!-- error: shared id --> <a id="2"/> <b id="3"/> <!-- error: shared id --> <a id="4"/> <b id="0"/> <!-- error: shared id --> <d id="6"/> <d id="7"/> <b id="3"/> <!-- error: shared id --> <c id="1"/> <!-- error: shared id --></Item>\[/code\]Schema, to be convert to XML 1.1. \[code\]<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="Item"> <xs:complexType> <xs:sequence maxOccurs="unbounded"> <xs:choice> <xs:element name="a"> <xs:complexType> <xs:attribute name="id" use="required"/> </xs:complexType> </xs:element> <xs:element name="b"> <xs:complexType> <xs:attribute name="id" use="required"/> </xs:complexType> </xs:element> <xs:element name="c"> <xs:complexType> <xs:attribute name="id" use="required"/> </xs:complexType> </xs:element> <xs:element name="d"> <xs:complexType> <xs:attribute name="id" use="required"/> </xs:complexType> </xs:element> </xs:choice> </xs:sequence> </xs:complexType> </xs:element></xs:schema>\[/code\]
 
Back
Top