I am trying those days to find a way to create a global attribute that will be used by all the elements in the schema and will serve as a key/unique attribute to them a well. look a the next example:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified" targetNamespace="http://www.NameSpace/Family" xmlns:tns="http://www.NameSpace/Family">
<xs:attribute name="id" type="xs:string"/>
<xs:complexType name="parentType">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Child" type="tns:childType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="tns:id" use="required"/>
</xs:complexType>
<xs:complexType name="childType">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
<xs:attribute ref="tns:id" use="required"/>
</xs:complexType>
<xs:element name="Family">
<xs:complexType>
<xs:sequence>
<xs:element name="Parent" type="tns:parentType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
now lets say for example, I create 1 parent with 2 kids, I want do define a key/unique on the id attribute so that all the elements id's (parents an childs) will be different from each other.
You can declare
idas having typexsd:IDlike this:Then you reference the declared attribute (like you already do):
You could also just declare the
idattribute on the types or elements directly.The
xs:IDtype imposesIDsemantics globally on allID-declared attributes in a document.