xs:ID — Definition of unique identifiers.
xs:enumeration, xs:length, xs:maxLength, xs:minLength, xs:pattern, xs:whiteSpace
<xs:simpleType name="ID" id="ID"> <xs:restriction base="xs:NCName"/> </xs:simpleType>
The purpose of the xs:ID
datatype is to define
unique identifiers that are global to a document and emulate the ID
attribute type available in the XML DTDs.
Unlike their DTD counterparts, W3C XML Schema ID datatypes can be used to define not only attributes, but also simple element content.
For both attributes and simple element content, the lexical domain of
these datatypes is the lexical domain of XML nonqualified names
(xs:NCName
).
Identifiers defined using this datatype are global to a document and provide a way to uniquely identify their containing element, whatever its type and name is.
The constraint added by this datatype beyond the
xs:NCName
datatype from which it is derived is
that the values of all the attributes and elements that have an ID
datatype in a document must be unique.
Applications that need to maintain a level of compatibility with DTDs should not use this datatype for elements but should reserve it for attributes.
The lexical domain (xs:NCName
) of this datatype
doesn’t allow the definition of numerical
identifiers or identifiers containing whitespaces.
W3C XML Schema provides another mechanism to define unique and key
constraints using the xs:unique
or
xs:key
elements when more flexibility is needed.
<xs:element name="book"> <xs:complexType> <xs:sequence> <xs:element name="isbn" type="xs:int"/> <xs:element name="title" type="xs:string"/> <xs:element name="author-ref"> <xs:complexType> <xs:attribute name="ref" type="xs:IDREF" use="required"/> </xs:complexType> </xs:element> <xs:element name="character-refs" type="xs:IDREFS"/> </xs:sequence> <xs:attribute name="identifier" type="xs:ID" use="required"/> </xs:complexType> </xs:element>