为什么XSD AnyAttibute无法正常工作?
我正在开发一个 XSD 文件来验证我的 XML,但 anyAttribute
规范没有按预期工作,至少没有按照文档报告的方式工作。
我在论坛上寻找过类似的问题,但没有发现重复的问题。
我想使用 xs:anyAttribute
扩展 menu
元素的指定属性,但在验证阶段,任何其他未指定的属性都会返回异常。
这是我的架构:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="https://www.github.com/overit-official/schemas" targetNamespace="https://www.github.com/overit-official/schemas">
<xs:element name="menu">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs = 'unbounded'></xs:any>
</xs:sequence>
<xs:attribute name="layer" type="xs:string" use="required"/>
<xs:attribute name="label" type="xs:string"/>
<xs:attribute name="icon" type="xs:string"/>
<xs:attribute name="priority" type="xs:string"/>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
</xs:schema>
这是我的 XML 片段:
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns="https://www.github.com/overit-official/schemas"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.github.com/overit-official/schemas https://www.github.com/overit-official/schemas/geocall-menu.xsd"
layer=""
label="Main menu"
icon="../r/std/icons/cartelle64.png"
mycustom="foo"
priority="3">
...
</menu>
当我验证 XML 时,出现此错误:
cvc-complex-type.3.2.2:不允许出现属性“mycustom” 在元素“菜单”中。
我缺少什么?
I'm developing an XSD file to validate my XMLs and the anyAttribute
specification doesn't work as expected, at least as how the documentation reports.
I've looked for similar questions or issues on the forum but I found no duplicate.
I want to extend the specified attributes for the menu
element with the xs:anyAttribute
but in the validation phase, any other nonspecified attributes return an exception.
This is my schema:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="https://www.github.com/overit-official/schemas" targetNamespace="https://www.github.com/overit-official/schemas">
<xs:element name="menu">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs = 'unbounded'></xs:any>
</xs:sequence>
<xs:attribute name="layer" type="xs:string" use="required"/>
<xs:attribute name="label" type="xs:string"/>
<xs:attribute name="icon" type="xs:string"/>
<xs:attribute name="priority" type="xs:string"/>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
</xs:schema>
Here a snippet of my XML:
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns="https://www.github.com/overit-official/schemas"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.github.com/overit-official/schemas https://www.github.com/overit-official/schemas/geocall-menu.xsd"
layer=""
label="Main menu"
icon="../r/std/icons/cartelle64.png"
mycustom="foo"
priority="3">
...
</menu>
When I validate the XML I get this error:
cvc-complex-type.3.2.2: Attribute 'mycustom' is not allowed to appear
in element 'menu'.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
processcontents的默认值
xs的属性:AnyAttribute
是strict
,它要求在XSD中定义属性,以便验证以验证经过。添加
processContents =“ Skip”
允许允许不确定的属性。另请参见
The default value for the
processContents
attribute ofxs:anyAttribute
isstrict
, which requires that the attribute be defined in the XSD in order for validation to pass.Add
processContents="skip"
to allow even undefined attributes.See also