如何使xml模式中的属性唯一?

前端之家收集整理的这篇文章主要介绍了如何使xml模式中的属性唯一?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使一个元素的属性像主键一样是唯一的.怎么做呢
这样的事情应该有效:
  1. <xs:element name="books" maxOccurs="unbounded">
  2. <xs:complexType>
  3. <xs:sequence>
  4. <xs:element name="book" maxOccurs="unbounded">
  5. <xs:complexType>
  6. <xs:attribute name="isbn" type="xs:string"/>
  7. </xs:complexType>
  8. </xs:element>
  9. </xs:sequence>
  10. </xs:complexType>
  11. <xs:unique name="unique-isbn">
  12. <xs:selector xpath="book"/>
  13. <xs:field xpath="@isbn"/>
  14. </xs:unique>
  15. </xs:element>

基本上,您可以使用< xs:unique>定义“唯一性”约束.元素,并定义这个唯一性应该适用的XPath.

有关更多信息,请参阅W3Schools entry on <xs:unique>.

猜你在找的XML相关文章