指定屬性或項目值 (或屬性或項目值的組合) 在指定範圍內必須是唯一的。值必須是唯一的或 Nil。
<unique
id = ID
name = NCName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (selector, field+))
</unique>
屬性
id
這個項目的 ID。id 值必須是型別 ID,且在包含此項目的文件中是唯一的。選擇性項目。
name
unique 項目的名稱。名稱必須是如 XML 命名空間規格中定義的無冒號名稱 (NCName)。名稱在識別條件約束集中必須是唯一的。
必要項目。
項目資訊
發生次數 |
一次 |
父項目 |
|
內容 |
備註
unique 項目必須依序包含下列項目。
selector |
selector 項目包含指定一組項目範圍的 XML 路徑語言 (XPath) 運算式。field 項目指定的值在這個範圍內必須是唯一值。 一定要有一個 (而且只有一個) selector 項目。 |
field |
每一個 field 項目包含 XPath 運算式。其指定的值 (屬性或項目值) 在 selector 項目中指定的項目集中必須是唯一的。 如果有多個 field 項目,這些 field 項目的組合必須是唯一的。此時,單一 field 項目的值在選取的項目範圍中可能是,也可能不是唯一的,但是所有欄位的組合必須是唯一的。 一定要有一或多個 field 項目。 |
範例
下列範例定義了有 ordersByCustomer 根項目的結構描述,可以包含 customerOrders 項目的未繫結順序。在 ordersByCustomer 項目中,unique 項目指定 customerID 屬性在所有 customerOrders 中必須是唯一的。
<xs:schema targetNamespace="http://tempuri.org/myschema/unique" elementFormDefault="qualified"
xmlns="http://tempuri.org/myschema/unique"
xmlns:mstns="http://tempuri.org/myschema/unique"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="customerOrderType">
<xs:sequence>
<xs:element name="item" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="itemID" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="CustomerID" type="xs:string"/>
</xs:complexType>
<xs:element name="ordersByCustomer">
<xs:complexType>
<xs:sequence>
<xs:element name="customerOrders" type="customerOrderType"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="oneCustomerOrdersforEachCustomerID">
<xs:selector xpath="mstns:customerOrders"/>
<xs:field xpath="@customerID"/>
</xs:unique>
</xs:element>
</xs:schema>
其他資源
如需詳細資訊,請參閱<W3C XML 結構描述第一部:結構建議事項>(英文),網址為:www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-all。