Schema validation not trimming strings before validating
Asked Answered
R

1

6

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>
...
Resonate answered 8/11, 2011 at 10:59 Comment(0)
D
3

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

Diplopia answered 8/11, 2011 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.