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

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

Defining references to unique identifiers

Derived from: xs:NCName

Primitive type: xs:string

Known subtypes: xs:IDREFS

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

Definition

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

Description

Data type xs:IDREF defines references to identifiers defined with data type xs:ID , thus emulating attribute type IDREF in XML DTDs, though it works for simple-content elements as well as attributes.

The lexical space of xs:IDREF , like that of xs:ID, consists of unqualified XML names (xs:NCName).

Beyond base data type xs:NCName, this data type requires every attribute or element value of type xs:IDREF to have a corresponding xs:ID value defined within the same document.

Restrictions

Applications requiring some compatibility with DTDs should reserve this data type for attributes rather than elements.

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

W3C XML Schema provides element xs:keyref as another mechanism for key-reference 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