我想使一个元素的属性像主键一样是唯一的.怎么做呢
这样的事情应该有效:
- <xs:element name="books" maxOccurs="unbounded">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="book" maxOccurs="unbounded">
- <xs:complexType>
- <xs:attribute name="isbn" type="xs:string"/>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:complexType>
- <xs:unique name="unique-isbn">
- <xs:selector xpath="book"/>
- <xs:field xpath="@isbn"/>
- </xs:unique>
- </xs:element>
基本上,您可以使用< xs:unique>定义“唯一性”约束.元素,并定义这个唯一性应该适用的XPath.
有关更多信息,请参阅W3Schools entry on <xs:unique>
.