XSD 验证显示我的没有定义

发布于 2025-01-17 02:18:29 字数 681 浏览 4 评论 0原文

我正在尝试使用 节点构建架构。当我验证时,它说插入的子节点未定义。我认为 any 允许我拥有未定义的子节点。

我的架构:

<xs:schema xmlns="Policy" targetNamespace="Policy" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Request">
    <xs:complexType>
      <xs:sequence>
        <xs:any />
      </xs:sequence>
      <xs:attribute name="Routing" type="xs:string" />
    </xs:complexType>
  </xs:element>
</xs:schema>

我的 XML:

<gp:Request Routing="foo" xmlns:gp="Policy">
  <bar/>
</gp:Request>

它标记 bar 节点。我做错了什么?

I'm trying to build a schema using an <xs:any /> node. When I validate it says the inserted child nodes aren't defined. I thought any allowed me to have undefined child nodes.

My schema:

<xs:schema xmlns="Policy" targetNamespace="Policy" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Request">
    <xs:complexType>
      <xs:sequence>
        <xs:any />
      </xs:sequence>
      <xs:attribute name="Routing" type="xs:string" />
    </xs:complexType>
  </xs:element>
</xs:schema>

My XML:

<gp:Request Routing="foo" xmlns:gp="Policy">
  <bar/>
</gp:Request>

It flags the bar node. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

陌生 2025-01-24 02:18:29

您正在见证 xs:any/@processContents="strict" 的预期行为,这是默认值。当@processContents 设置为strict 时,元素定义必须存在,并且 XML 中的元素必须针对该声明有效

请更改为

<xs:any processContents="lax" />

如果您希望仅当元素定义存在时才进行验证,或者

<xs:any processContents="skip" />

无论您是否在 XSD 中定义该元素,都希望不进行验证

。另请参阅

You're witnessing the expected behavior for xs:any/@processContents="strict", which is the default value. When @processContents is set to strict, the element definition must exist, and the element in the XML must be valid against that declaration.

Change to

<xs:any processContents="lax" />

if you want validation to occur only if the element definition exists, or

<xs:any processContents="skip" />

if you want no validation to take place regardless of whether the element is defined in the XSD.

See also

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