【问题标题】:XML Schema union ignore whiteSpace propertyXML Schema union 忽略 whiteSpace 属性
【发布时间】:2014-12-05 02:39:16
【问题描述】:

根据XML Schema specification of whitespace

对于所有数据类型·派生·由·联合·空白不直接应用;但是,·union· 类型的规范化行为由成功验证·union· 所依据的·memberTypes 之一上的 whiteSpace 值控制

对于字符串,保留空格的值

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

XML(注意空格):

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

XML Schema(注意模式限制):

<?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 错误。

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

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

【问题讨论】:

    标签: xml xsd xsd-validation


    【解决方案1】:

    谁说它有效?

    撒克逊人说:

    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,Saxon如果 xs:restriction 节点同时包含 xs:assertion 和 xs:enumeration,则失败。尝试根据断言验证枚举方面失败,并给出以下错误:Validation context required。为了重现此错误,您可以将此元素添加到 XML 模式:&lt;element name="e"&gt;&lt;simpleType&gt;&lt;restriction base="string"&gt;&lt;enumeration value="v"/&gt;&lt;assertion test="$value = 'v'"/&gt;&lt;/restriction&gt;&lt;/simpleType&gt;&lt;/element&gt;。请确认错误。
    • 谢谢。抱歉,我知道这不是报告错误的合适网站,但我不使用撒克逊邮件列表,也不是撒克逊注册用户。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    相关资源
    最近更新 更多