XML Schema unique element

Definition and Usage

The unique element specifies that the attribute or element value (or combination of attribute or element value) must be unique within the specified range. The value must be unique or zero.

The unique element must sequentially contain the following elements:

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

selector element

There must be one and only one selector element.

field element

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

If there are multiple field elements, the combination of 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.

There must be one or more field elements.

Element information

Occurrence Once
Parent element element
Content annotation, field, selector

Syntax

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

(? The symbol declaration can appear zero or one time in the unique element.)

Attribute Description
id Optional. Ορίζει το μοναδικό ID του στοιχείου.
name Required. Συνιστάται όνομα για το στοιχείο.
any attributes Οptional. Ορίζει οποιαδήποτε άλλη ιδιότητα με non-schema ονομαστικό χώρο.

Παράδειγμα

Παράδειγμα 1

Αυτή είναι μια απλή τύπος που συγχωνεύει δύο απλούς τύπους:

<xs:element name="jeans_size">
  <xs:simpleType>
    <xs:union memberTypes="sizebyno sizebystring" />
  </xs:simpleType>
</xs:element>
<xs:simpleType name="sizebyno">
  <xs:restriction base="xs:positiveInteger">
    <xs:maxInclusive value="42"/>
  </xs:restriction>
</xs:simpleType>
<xs:simpleType name="sizebystring">
  <xs:restriction base="xs:string">
    <xs:enumeration value="small"/>
    <xs:enumeration value="medium"/>
    <xs:enumeration value="large"/>
  </xs:restriction>
</xs:simpleType>