XML technologies / XML Schema / XML Schema element reference / xs:unique
(Excerpt from “XML Schema” by Eric van der Vlist)
Defining a uniqueness constraint.
<xs:unique
id = xs:ID
name = xs:NCName
{beliebige Attribute mit einem Nicht-Schema-Namensraum}
>
Content: ((xs:annotation?), (xs:selector, xs:field+))
</xs:unique>May occur within: xs:simpleType (local definition), xs:simpleType (global definition)
Description
xs:unique defines simple or composite constraints uniquely identifying each element in a selected list of subelements within a root’s scope, provided the fields occur in that element.
xs:unique and xs:key are very similar. Like keys defined with xs:key, constraints defined with xs:unique are unique within their root’s scope and can be referenced by xs:keyref . The only difference between xs:unique and xs:key is that xs:unique identifiers may be undefined for selected elements, whereas xs:key keys must be defined for every selected element.
The constraint’s root is the element where it is defined. Choose it carefully: uniqueness is checked only among element nodes below this root. A repeated root permits local constraints unique only below each occurrence. For a document-wide constraint, using the document element as root may be less error-prone.
The contribution of xs:unique to the PSVI is a node table in each root occurrence listing its key sequences. Its scope includes the containing root and its ancestors. This determines key-reference behavior and affects the choice of root for a referenced constraint; see xs:keyref.
Restrictions
These XPath based constructs do not follow the object-oriented, namespace-aware general principles of W3C XML Schema. XPath expressions are independent of the content model, and constraints on elements of all possible namespaces must be specified in the schema for the namespace of the root containing the key constraint.
Example
<xs:element name="library">
<xs:complexType>
.../...
</xs:complexType>
<xs:unique name="book">
<xs:selector xpath="book"/>
<xs:field xpath="isbn"/>
</xs:unique>
</xs:element>Attributes
id
Element ID according to W3C XML Schema.
name
Uniqueness-constraint name.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de