XML Schema unique element
Definition and Usage
The unique element specifies that the attribute or element value (or combination of attribute or element values) must be unique within the specified range. The value must be unique or zero.
The unique element must sequentially contain the following elements:
selector element
The selector element contains an XPath expression that specifies a set of elements in which the value specified by the field element must be unique.
There must be one and only one selector element.
field element
Each field element contains an XPath expression that specifies a unique value (attribute or element value) that must be present 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.
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 indicates that this element can appear zero or one time within the unique element.)
Attribute | Description |
---|---|
id | Optional. Defines a unique ID for the element. |
name | Required. Specifies the name for the element. |
any attributes | Optional. Defines any other attributes with a non-schema namespace. |
Instance
Example 1
This example is a simple type that merges two simple types:
<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>