XML Schema union ignore whiteSpace property
根据 XML Schema 规范的空格:
For all datatypes ·derived· by ·union· whiteSpace does not apply directly; however, the normalization behavior of ·union· types is controlled by the value of whiteSpace on that one of the ·memberTypes· against which the ·union· is successfully validated.
和
for string the value of whiteSpace is preserve
基于此,下面的示例应该是无效的,因为应该保留字符串的空格,并且不应该满足模式。然而它是有效的。所以,我的问题是?为什么这个 XML 对这个模式有效?
XML(注意空格):
1
2 |
<?xml version=“1.0” encoding=“UTF-8” ?>
<elem> Hello world</elem> |
XML Schema(注意模式限制):
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version=“1.0” encoding=“UTF-8” ?>
<xs:schema xmlns:xs=“http://www.w3.org/2001/XMLSchema”> <xs:simpleType name=“myUnion”> <xs:union memberTypes=“xs:string”> </xs:union> </xs:simpleType> <xs:element name=“elem”> |
编辑:Xerces 说它有效,Saxon 说它无效。这似乎是一个 Xerces 错误。
但是,如果我们这样定义联合:
1
2 3 4 5 6 7 8 9 |
<xs:simpleType name=“myUnion”>
<xs:union> <xs:simpleType> <xs:restriction base=“xs:string”> <xs:whiteSpace value=“collapse”/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType> |
再次,Xerces 说它有效,Saxon 说它无效。但这一次它似乎是一个撒克逊错误(因为应该折叠空格并且应该满足模式)。 ?你怎么看?
谁说它有效?
撒克逊人说:
1
2 3 4 5 6 7 8 9 10 |
Processing file:/Users/mike/Desktop/temp/test.xml
Validation error on line 2 of test.xml: XSD: The content” Hello world” of element <elem> does not match the required simple type. Value” Hello world” contravenes the pattern facet“Hello world” of the type of element elem Validating /elem[1] See http://www.w3.org/TR/xmlschema11-2/#cvc-datatype-valid clause 1 Validation error on line 2 column 37 of test.xml: XSD: One or more validation errors were reported Validation unsuccessful |
而撒克逊人通常会做对 ;-)
- 看看新的例子,其中撒克逊人似乎是错误的,而 Xerces 似乎是正确的。
- 是的,我认为你可能是对的。我实际上发现很难在 XSD 第 2 部分中找到将它们联系在一起的明确文本:模式方面被定义为对”词汇空间中的值”进行操作,而空白方面决定了”规范化值” “;我不是 100% 确定这些是同一件事。然而,第 1 部分非常清楚地表明,它必须是对约束有效的规范化值,所以我猜想关于应用于词汇空间的模式的内容只是未能采用该术语。
- 谢谢你。标记为已接受,因为我的第一个示例不应该是有效的,Xerces 验证器是错误的。似乎枚举方面发生了类似的事情,当限制从 union 派生的 simpleType 时也可能出现这种情况,并且 XSD 1.1 中的断言也可能发生同样的情况。
- 我发现了另一个 Saxon 错误,现在在 Saxon – EE 9.6.0.5 中:在 XSD 中,给定使用 xs:restriction 定义的 xs:simpleType,如果 xs:restriction 节点同时包含 xs:assertion 和 xs,则 Saxon 失败:枚举。尝试根据断言验证枚举方面失败,并给出以下错误:Validation context required。为了重现此错误,您可以将此元素添加到 XML 架构:<element name=”e”><simpleType><restriction base=”string”><enumeration value=”v”/></restriction></simpleType></element>。请确认错误。
- 谢谢。对不起,我知道这不是报告错误的合适网站,但我不使用撒克逊邮件列表,也不是撒克逊注册用户。
- 欢迎您在此处记录它,如果我们注意到它,我们将把它捡起来,但我们通过我们自己的错误跟踪器管理解决方案,除非您访问该跟踪器,否则您将不会获得有关进度的反馈。
来源:https://www.codenong.com/27307880/