将属性值限制为子属性(引用现有值)
我有一个像这样的 xml:
<userCredentials default="user1" >
<userCredential username="user1" password="pwd" />
<userCredential username="user2" password="pwd" />
<userCredential username="user3" password="pwd" />
</userCredentials>
如何将属性 default
的值限制为 //userCredential[@username]
值之一?
下面是我的 xsd 方案:
<xs:complexType name="userCredential">
<xs:attribute name="username" type="xs:string" use="required" />
<xs:attribute name="password" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="userCredentials">
<xs:sequence>
<xs:element name="userCredential" type="tns:userCredential" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="default" use="required" >
<xs:simpleType>
<xs:restriction>
<xs:pattern value="" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
I have a xml like this:
<userCredentials default="user1" >
<userCredential username="user1" password="pwd" />
<userCredential username="user2" password="pwd" />
<userCredential username="user3" password="pwd" />
</userCredentials>
How can I resrict value of attribute default
to be only one of //userCredential[@username]
value?
Below my xsd scheme:
<xs:complexType name="userCredential">
<xs:attribute name="username" type="xs:string" use="required" />
<xs:attribute name="password" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="userCredentials">
<xs:sequence>
<xs:element name="userCredential" type="tns:userCredential" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="default" use="required" >
<xs:simpleType>
<xs:restriction>
<xs:pattern value="" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是完全有可能的。下面是一个 XSD 示例,它强制块内所有用户名的唯一性,并且还要求
default
属性引用这些值之一:This is completely possible. Here's an example XSD that enforces the uniqueness of all usernames within the block and also requires that the
default
attribute references one of those values: