XML technologies / XML Schema / Data type reference / xs:ID

(Excerpt from “XML Schema” by Eric van der Vlist)

Defining a unique identifier

Derived from: xs:NCName

Primitive type: xs:string

Known subtypes: none

Facets: xs:enumeration, xs:length, xs:maxLength, xs:minLength, xs:pattern, xs:whiteSpace

Definition

<xs:simpleType name="ID" id="ID">
    <xs:restriction base="xs:NCName"/>
</xs:simpleType>

Description

The purpose of data type xs:ID is to define document-wide unique identifiers, emulating the ID attribute type available in XML DTDs.

Unlike their DTD counterparts, W3C XML Schema’s ID data types can define not only attributes but also simple element content.

For both attributes and simple element content, these types’ lexical space is that of unqualified XML names (xs:NCName).

Identifiers defined with this type are global within a document and uniquely identify their containing element, regardless of its type or name.

The additional restriction beyond base data type xs:NCName, from which it is derived, is that values of all attributes and elements of data type xs:ID must be unique.

Restrictions

Applications needing some DTD compatibility should reserve this type for attributes rather than elements.

The lexical space (xs:NCName) does not permit numeric identifiers or identifiers containing whitespace.

W3C XML Schema provides elements xs:unique and xs:key as another mechanism for uniqueness and key constraints when more flexibility is needed.

Example

<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>

   

 

 

 

back to top