특성 또는 요소 값(또는 값 집합)이 지정된 범위 내에서 키이어야 함을 지정합니다. 키의 범위는 인스턴스 문서에서 포함하는 element입니다. 키는 지정한 범위 내에서 nillable이 아닌 고유한 값으로 항상 존재해야 합니다.
<key
id = ID
name = NCName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (selector, field+))
</key>
특성
id
이 요소의 ID입니다. id 값은 ID 형식이어야 하며 이 요소를 포함하는 문서 내에서 고유한 값이어야 합니다.선택적 항목입니다.
name
key 요소의 이름입니다. 이 이름은 XML 네임스페이스 사양에 정의된 대로 NCName(No-Colon-Name)이어야 합니다.이름은 identity 제약 조건 집합 내에서 고유해야 합니다.
필수 항목입니다.
요소 정보
발생 횟수 |
제한 없음 |
부모 요소 |
|
내용 |
주의
key 요소에는 다음 요소가 순서대로 포함되어야 합니다.
selector |
selector 요소에는 요소 집합을 지정하는 XPath(XML Path Language) 식이 포함되며 필드에 지정된 값은 이 요소 집합에서 고유해야 합니다. selector 요소는 하나만 있어야 합니다. |
field |
각 field 요소에는 selector 요소에 지정된 요소 집합에 대해 고유한 값(특성 또는 요소 값)을 지정하는 XPath 식이 포함됩니다. field 요소가 여러 개인 경우에는 field 요소의 조합이 고유해야 합니다. 이 경우 선택한 요소에서 특정 field 요소의 값은 고유하지 않을 수도 있으나 모든 필드의 조합은 고유해야 합니다. field 요소는 하나 이상이어야 합니다. |
예제
다음 예제에서는 이 스키마에서 key 요소에 해당하는 keyref 요소를 정의합니다.
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="namespace1"
xmlns:r="namespace1"
elementFormDefault="qualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="A" type="r:A" maxOccurs="unbounded">
<xs:keyref name="dummy" refer="r:pNumKey">
<xs:selector xpath="part"/>
<xs:field xpath="@ref-number"/>
</xs:keyref>
</xs:element>
<xs:element name="B" type="r:B"/>
</xs:sequence>
</xs:complexType>
<xs:key name="pNumKey">
<xs:selector xpath="r:B/r:part"/>
<xs:field xpath="@key-number"/>
</xs:key>
</xs:element>
<xs:complexType name="A">
<xs:sequence>
<xs:element name="part" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="ref-number" type="xs:integer"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="B">
<xs:sequence>
<xs:element name="part" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="key-number" type="xs:integer"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
입력: key.xml
<root xmlns="namespace1">
<A>
<!-- if the ref-number is not equal to one of the key-number, the validation will give error -->
<part ref-number="1"/>
</A>
<A>
<!-- if the ref-number is not equal to one of the key-number, the validation will give error -->
<part ref-number="2"/>
</A>
<B>
<part key-number="1"/>
<part key-number="2"/>
<part key-number="3"/>
</B>
</root>
관련 자료
자세한 내용은 www.w3.org/TR/2001/REC-xmlschema-1-20010502/\#element-all에 있는 Structures Recommendation을 참조하십시오.