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.
在自动格式化后,我在验证XML文件时遇到问题。在验证字符串之前,验证不会修剪字符串。这是.NET的XML验证实现中的错误还是这种被接受的行为?如果它是可接受的行为,那么通常如何处理这样的情况,因为在我看来,这两个XML文件是等价的。
My XSD:
我的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):
格式化之前的我的XML(验证通过):
...
<ItemType>ItemA</ItemType>
...
After formatting (validation fails):
格式化后(验证失败):
...
<ItemType>
ItemA
</ItemType>
...
1 个解决方案
#1
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).
鉴于模式的定义方式,验证器的行为正确。您需要停止格式化程序对内容采取此类*,或者您需要更改模式 - 例如,通过使ItemTypeData限制xs:token而不是xs:string(在xs:token中,前导和尾随空格被视为微不足道)。
#1
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).
鉴于模式的定义方式,验证器的行为正确。您需要停止格式化程序对内容采取此类*,或者您需要更改模式 - 例如,通过使ItemTypeData限制xs:token而不是xs:string(在xs:token中,前导和尾随空格被视为微不足道)。