比方說,我有以下XML文件:唯一約束
<authors>
<author>a1</author>
<author>a2</author>
<lastmodified>2010</lastmodified>
</authors>
和XML schema片斷:
<xs:element name="authors" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="author" maxOccurs="unbounded" type="xs:string"> </xs:element>
<xs:element name="lastmodified" type="xs:date" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueAuthor">
<xs:selector xpath="."/>
<xs:field xpath="author"/>
</xs:unique>
</xs:element>
我要的是做一個約束,將不會允許兩個相同作者的價值觀,但上面的那個不行。我究竟做錯了什麼?
唯一性約束有一定的優勢超過'XS:ID ',請參閱http://www.xml.com/pub/a/2002/11/20/schemas.html#identity_constraints – DaveFar