XSD 验证显示我的没有定义
我正在尝试使用
节点构建架构。当我验证时,它说插入的子节点未定义。我认为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在见证
xs:any/@processContents="strict"
的预期行为,这是默认值。当@processContents
设置为strict
时,元素定义必须存在,并且 XML 中的元素必须针对该声明有效。请更改为
如果您希望仅当元素定义存在时才进行验证,或者
无论您是否在 XSD 中定义该元素,都希望不进行验证,
。另请参阅
You're witnessing the expected behavior for
xs:any/@processContents="strict"
, which is the default value. When@processContents
is set tostrict
, the element definition must exist, and the element in the XML must be valid against that declaration.Change to
if you want validation to occur only if the element definition exists, or
if you want no validation to take place regardless of whether the element is defined in the XSD.
See also