Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schema validation not trimming strings before validating

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>
...
like image 967
Daniel Hilgarth Avatar asked Nov 08 '11 10:11

Daniel Hilgarth


1 Answers

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

like image 72
Michael Kay Avatar answered Oct 20 '22 13:10

Michael Kay