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, it would be illegal for an fn element's fnid attribute to have the same value as a section element's id attribute. Values of type xs:ID follow the same rules as the xs:NCName type; they must start with a letter or underscore, and can only contain letters, digits, underscores, hyphens, and periods.

Because xs:ID is ultimately derived from xs:string, xs:ID values can be compared and used like strings. For more information on working with IDs, see "Working with IDs" in Chapter 20.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.83.62