I have a problem with validating my XML file, after it has been automatically formatted. The validation doesn't trim the string before validating it. Is this a bug in the implementation of the XML validation of .NET or is this accepted behavior? If it is accepted behavior, how are cases like this normally handled, because in my opinion, the two XML files are equivalent.
My XSD:
<xs:schema ...>
...
<xs:simpleType name="ItemTypeData">
<xs:restriction base="xs:string">
<xs:enumeration value="ItemA" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
My XML before formatting (validation passes):
...
<ItemType>ItemA</ItemType>
...
After formatting (validation fails):
...
<ItemType>
ItemA
</ItemType>
...
Your validator is behaving correctly, given the way the schema is defined. You either need to stop the formatter taking such liberties with the content, or you need to change the schema - for example by making ItemTypeData a restriction of xs:token rather than xs:string (in xs:token, leading and trailing whitespace is considered insignificant).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With