如何验证 xml 以便只有实际存在的元素才能用作属性?

发布于 2024-09-26 05:41:18 字数 721 浏览 0 评论 0原文

所以,基本上我想做的是模拟模式验证的“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-10-03 05:41:18

我不是 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 type ID, and the name attribute on subordinate 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文