Chapter 9. Defining Uniqueness, Keys, and Key References

Like any storage system, a XML document needs to provide ways to identify and reference pieces of the information it contains. In this chapter, we will present and compare the two features that allow XML to do so with W3C XML Schema. One directly emulates the ID, IDREF, and IDREFs attribute types from the XML DTDs, while the other was introduced to provide more flexibility through the use of XPath expressions.

The first way to describe identifiers and references with W3C XML Schema is inherited from XML’s DTDs. We already discussed this in Chapter 5: the xs:ID , xs:IDREF , and xs:IDREFS datatypes introduced in W3C XML Schema emulate the behavior of the XML DTD’s ID, IDREF, and IDREFS attribute types.

Unlike their DTD counterparts, these simple types can be used to describe both elements and attributes, but inherit the other restrictions from the DTDs: their lexical space is the same as the unqualified XML name (known as the xs:NCName datatype), and they are global to a document, meaning that you won’t be allowed to use the same ID value to identify, for instance, both an author and a character within the same document.

The restriction on the lexical space can often prevent you from using an existing node as an identifier. For instance, in our library, we will not be able to use an ISBN number as an ID since xs:NCName cannot start with a number and whitespace is prohibited. We will therefore need to create ...

Get XML Schema 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.