如何在xml模式中使属性唯一? [英] how to make an attribute unique in xml schema?

查看:30
本文介绍了如何在xml模式中使属性唯一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个元素的属性像主键一样是唯一的.怎么做?

i wanna make an attribute of an element to be unique like primary key. how to make it?

推荐答案

这样的事情应该可行:

<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.

Basically, you can define a "uniqueness" constraint using a <xs:unique> element and define what XPath this uniqueness should apply to.

请参阅 W3Schools 的 条目关于 了解更多信息.

See W3Schools' entry on <xs:unique> for more info.

这篇关于如何在xml模式中使属性唯一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆