xs:ID

The type xs:ID represents a unique identifier in an XML document. It is most commonly used as the type of an attribute that serves as an identifier for the element that carries it. Example B-1 shows an XML document that contains some ID attributes, namely the id attribute of the section element, and the fnid attribute of the fn element. Each section and fn element is uniquely identified by an ID value, such as fn1, preface, or context.

The example assumes that this document was validated with a schema that declares these attributes to be of type xs:ID. Having the local name id is not enough to make an attribute an xs:ID; the attribute must be declared in a schema to have the type ID. In fact, the name is irrelevant; an attribute named foo can have the type xs:ID, and an attribute named id can be of type xs:integer.

Example B-1. XML document with IDs and IDREFs (book.xml)

<book>
  <section id="preface">This book introduces XQuery...
    The examples are downloadable<fnref ref="fn1"/>...
  </section>
  <section id="context">...</section>
  <section id="language">...Expressions, introduced
   in <secRef refs="context"/>, are...
  </section>
  <section id="types">...As described in
    <secRef refs="context language"/>, you can...
  </section>
  <fn fnid="fn1">See http://datypic.com.</fn>
</book>

The values of attributes of type xs:ID must be unique within the entire XML document. This is true even if two xs:ID values appear in attributes with different names, or on elements with different names. For example, ...

Get XQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.