问题
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