XML 架构联合忽略 whiteSpace 属性 [英] XML Schema union ignore whiteSpace property

查看:35
本文介绍了XML 架构联合忽略 whiteSpace 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据空白的XML Schema规范:

对于所有数据类型·派生·由·联合·空格不直接适用;然而,·union· 类型的规范化行为由·memberTypes· 之一的whiteSpace 值控制,而该·union· 是根据该值成功验证的.

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.

对于字符串,whiteSpace 的值是保留的

基于此,以下示例应该无效,因为应该保留字符串的空格,并且不应该满足模式.然而它是有效的.所以,我的问题是¿为什么这个 XML 对这个架构有效?

Based on that, the following example should not be valid as the whitespace of the string should be preserved, and the pattern should not be satisfied. However its valid. So, my querstion is ¿why is this XML valid against this schema?

XML(注意空格):

<?xml version="1.0" encoding="UTF-8" ?>
<elem>  Hello           world</elem>

XML Schema(注意模式限制):

XML Schema (notice the pattern restriction):

<?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">
        <xs:simpleType>
            <xs:restriction base="myUnion">
                <xs:pattern value="Hello world" />
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
</xs:schema>

<小时>

Xerces 说它有效,Saxon 说它无效.这似乎是一个 Xerces 错误.


EDIT : Xerces says its valid, Saxon says its not valid. Thats seems to be a Xerces bug.

但是,如果我们这样定义联合:

However, if we define the union like this:

<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 说它无效.但这一次它似乎是撒克逊人的错误(因为应该折叠空白并且应该满足模式).¿你怎么看?

Again, Xerces says its valid, Saxon says its not valid. But this time its seems to be a Saxon bug (as the whitespace should be collapsed and the pattern should be satisfied). ¿What do you think?

推荐答案

谁说它有效?

撒克逊人说:

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

撒克逊人通常会做对;-)

and Saxon usually gets it right ;-)

这篇关于XML 架构联合忽略 whiteSpace 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆