如何验证 xml 以便只有实际存在的元素才能用作属性?
所以,基本上我想做的是模拟模式验证的“ref”属性。例如,我有以下 XML:
<node name="parent">
<subordinate name="child3" />
</node>
<node name="child1" />
<node name="child2" />
我希望我的模式将其标记为无效,因为“child3”不是可用的“节点”选项之一(未指定)。我有以下架构:
<xs:element name="node" nillable="false">
<xs:complexType>
<xs:attribute ref="name" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="subordinate" nillable="false">
<xs:complexType>
<xs:attribute ref="name" use="required" />
</xs:complexType>
</xs:element>
但我不确定如何指定“从属”元素的“名称”属性必须来自另一个定义的“节点”元素。
感谢您提供的任何帮助!
So, basically what I want to do is to emulate the "ref" attribute of schema validation. I have the following XML, for example:
<node name="parent">
<subordinate name="child3" />
</node>
<node name="child1" />
<node name="child2" />
And I want this to be flagged by my schema as invalid, since "child3" isn't one of the available 'node' options (it wasn't specified). I have the following schema:
<xs:element name="node" nillable="false">
<xs:complexType>
<xs:attribute ref="name" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="subordinate" nillable="false">
<xs:complexType>
<xs:attribute ref="name" use="required" />
</xs:complexType>
</xs:element>
But I'm not sure how to specify that the "subordinate" element's "name" attribute must come from another defined "node" element.
Thanks for any help you can give!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 XSD 专家,但我相信您希望将
node
上的 name 属性声明为 XSD 类型ID
,并将subscribed< 上的 name 属性声明为 XSD 类型
ID
。 /code> 作为 IDREF。编辑:添加引用
ID/IDREF 数据类型: http://www.w3.org/TR /xmlschema-2/#ID
ID/IDREF 验证:http: //www.w3.org/TR/xmlschema-1/#cvc-id
I'm not an XSD expert, but I believe you want to declare the name attribute on
node
as an XSD typeID
, and the name attribute onsubordinate
as an IDREF.Edit: Added references
ID/IDREF datatypes: http://www.w3.org/TR/xmlschema-2/#ID
ID/IDREF validation: http://www.w3.org/TR/xmlschema-1/#cvc-id