我想让元素的属性像主键一样唯一。怎么做到的?
最佳答案
像这样的东西应该可以工作:
<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>
了解更多信息。
关于xml - 如何使属性在 xml 模式中唯一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3387133/