次の方法で共有


<xsd:unique> 要素

指定したスコープ内で、属性値または要素値 (あるいは属性値または要素値の組み合わせ) が一意である必要があることを指定します。値は一意または null である必要があります。

<unique
  id = ID 
  name = NCName 
  {any attributes with non-schema Namespace}...>
Content: (annotation?, (selector, field+))
</unique>

属性

  • id
    この要素の ID。id の値は ID 型である必要があり、この要素を含んでいるドキュメント内で一意である必要があります。

    省略可能です。

  • name
    unique 要素の名前。この名前は、『XML Namespaces』の仕様に定義されているとおり、コロンを含まない名前 (NCName) である必要があります。

    この名前は、ID 制約セット内で一意である必要があります。

    必ず指定します。

要素情報

出現回数

1 回

親要素

element

コンテンツ

annotationfieldselector

解説

unique 要素には、次の要素を順に含める必要があります。

selector

selector 要素には、要素セットを指定する XPath (XML Path Language) 式を指定します。field 要素で指定した値は、この要素セットの範囲で一意である必要があります。

selector 要素は、必ず 1 つ存在する必要があり、また 2 つ以上存在することはできません。

field

個々の field 要素には、selector 要素で指定された要素の集合で一意でなければならない値 (属性値または要素値) を指定する XPath 式が含まれています。

field 要素が複数存在する場合、それらの field 要素の組み合わせは一意である必要があります。field 要素が複数存在する場合、1 つの field 要素の値は、選択した要素の範囲で一意であっても一意でなくてもかまいませんが、すべてのフィールドの組み合わせは一意である必要があります。

1 つ以上の 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>

その他のリソース

詳細については、www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-all で公開されている、W3C 勧告『XML Schema Part 1: Structures』を参照してください。

参照

リファレンス

XML スキーマ (XSD) リファレンス
XML スキーマの要素