XML Schema key element

Definition and Usage

The key element specifies that the attribute or element value (or a set of values) must be a key within the specified range. The range of the key is the element contained in the instance document. The key means that the data within the specified range should be unique, non-zero, and always present.

The key element must sequentially contain the following elements:

selector element:

There must be exactly one selector element.

The selector element contains an XPath expression that specifies an element set in which the value specified by the field must be unique.

field element

There must be one or more field elements.

Each field element contains an XPath expression that specifies the unique value (attribute or element value) that must be for the element set specified by the selector element.

If there are multiple field elements, the combination of the field elements must be unique. In this case, the value of a single field element may not be unique for the selected element, but the combination of all fields must be unique.

Element Information

Occurrence Times Unrestricted
Parent Element element
Content annotation, field, selector

Syntax

<key
id=ID
name=NCName
any attributes
>
(annotation?,(selector,field+))
</key>

(The '?' symbol declares that the element can appear zero or one time, the '+' symbol declares that the element must appear one or more times.)

Attributes Description
id Optional. Specifies a unique ID for the element.
name Required. Specifies the name of the key element.
any attributes Optional. Specifies any other attributes with non-schema namespace.