6.12. Identity Constraint Definitions

An XML schema generally validates the structure of an XML instance in terms of element nesting and attributes. The XML schema also validates content primarily in the form of simple types. Identity constraints provide an additional mechanism to validate contents. The three types of elements for creating identity constraints are unique, key, and keyref.

A unique element specifies that repeated elements are unique given the values of one or a combination of keys. For example, Listing 6.8 demonstrates that a partNumber can appear only once with a particular value in the entire completePartList.

Listing 6.8. Unique Part Numbers (sdDemo.xsd)
 <xsd:element name="completePartList"> <xsd:complexType> <xsd:sequence> ...

Get XML Schema Complete Reference, The 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.