XML Schema union ignore whiteSpace property

与世无争的帅哥 提交于 2019-12-12 02:55:47

问题


According to XML Schema specification of whitespace:

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.

and

for string the value of whiteSpace is preserve

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 (notice the whitesepaces):

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

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>

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>

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?


回答1:


Who says it's valid?

Saxon says:

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 ;-)



来源:https://stackoverflow.com/questions/27307880/xml-schema-union-ignore-whitespace-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!