Name

xs:key

Synopsis

<xs:key
  id = "ID"
  name = "NCName" >
  <!-- (xs:annotation?, (xs:selector, xs:field+) ) -->
</xs:key>

Keys establish uniqueness and co-occurrence constraints among various nodes in the document. For example, you can define a key for an Employee element based on its EmployeeNumber child element and then require that each Assignment element have a team attribute whose contents are a list of employee keys.

The xs:key element defines a new key. It appears only as a child of an xs:element element following the element’s type. The name of the key is specified by the name attribute. The elements that have a value for this key are identified by the xs:selector child element. The value of the key for each of these nodes is given by the xs:field child element and must be unique within that set. If there is more than one xs:field child element, then the key is formed by concatenating the value of each field.

Get XML in a Nutshell, 3rd Edition 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.