【发布时间】:2017-01-06 10:30:29
【问题描述】:
我有一个有效的 xsd 拒绝验证包含无效空格的 XML 实例(有关详细信息,请参见下文,但包括回车符 (#xD)、换行符 (#xA) 或制表符 (#x9) 字符,否开始或结束空格 (#x20) 字符,或两个或多个相邻空格字符的序列)。
XSD 示例:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://www.example.com"
xmlns:test="http://www.example.com">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
<xs:element name="test-token" type="test:Tokenized500Type"></xs:element>
<xs:simpleType name="Tokenized500Type">
<xs:annotation>
<xs:documentation>An element of this type has minimum length of one character, a max of 500, and may not
contain any of: the carriage return (#xD), line feed (#xA) nor tab (#x9) characters, shall
not begin or end with a space (#x20) character, or a sequence of two or more adjacent space
characters.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:maxLength value="500"/>
<xs:minLength value="1"/>
<xs:pattern value="\S+( \S+)*"/>
</xs:restriction>
</xs:simpleType>
我用上面的文字空白字符对此进行了测试。
如果 XML 实例在相关元素内容中包含转义空格怎么办?这会导致验证错误吗?
这是一个带有转义版本的示例:
<?xml version="1.0" encoding="UTF-8"?>
<test-token xmlns="http://www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com"> </test-token>
另见:
【问题讨论】:
-
您能否提供 XSD 和示例 XML,并说明您遇到/预期的错误是什么
-
谢谢,我已经添加了。因为看起来 就像文字 nl 一样使此架构的实例无效,除非您愿意,否则我会回答我的问题。
标签: validation xsd escaping whitespace tokenize