XML Schema unique 元素
定義和用法
unique 元素指定屬性或元素值(或者屬性或元素值的組合)在指定范圍內(nèi)必須是唯一的。 該值必須唯一或?yàn)榱恪?/p>
unique 元素必須按順序包含下列元素:
selector 元素
selector 元素包含 XPath 表達(dá)式,指定一個元素集,在其中由 field 元素指定的值必須唯一。
必須有一個且只有一個 selector 元素。
field 元素
每一個 field 元素均包含一個 XPath 表達(dá)式,指定對于由 selector 元素指定的元素集而言必須唯一的值(屬性或元素值)。
如果有多個 field 元素,則 field 元素的組合必須是唯一的。 在此情況下,單個 field 元素的值對于選定元素不一定是唯一的,但所有字段的組合必須是唯一的。
必須有一個或多個 field 元素。
元素信息
出現(xiàn)次數(shù) | 一次 |
父元素 | element |
內(nèi)容 | annotation、field、selector |
語法
<unique id=ID name=NCName any attributes > (annotation?,(selector,field+)) </unique>
(? 符號聲明在 unique 元素中該元素可出現(xiàn)零次或一次。)
屬性 | 描述 |
---|---|
id | 可選。規(guī)定該元素的唯一的 ID。 |
name | 必需。為該元素指定名稱。 |
any attributes | 可選。規(guī)定帶有 non-schema 命名空間的任何其他屬性。 |
實(shí)例
例子 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>