我使用以下 XmlSchema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.test.com/XmlValidation"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:m="http://www.test.com/XmlValidation">
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element name="testElement" type="m:requiredStringType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="requiredStringType">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
它定义了一个必须至少有一个字符长的 requiredStringType 并且还定义了空格折叠。
当我验证以下 Xml 文档时,验证成功:
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.text.com/XmlValidation">
<testElement> </testElement>
</test>
w3.org 定义了空格折叠:
“在替换隐含的处理之后,#x20 的连续序列被折叠为单个 #x20,并且前导和尾随 #x20 被删除。”
这是否意味着 3 个空格被折叠为 1 个或 0 个空格?在 XmlSpy 中验证失败,在 .Net 中验证成功。