XmlSchema 空白崩溃:多个空白会发生什么? [英] XmlSchema Whitespace collapse: What happens to multiple whitespaces?

查看:41
本文介绍了XmlSchema 空白崩溃:多个空白会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下 XmlSchema:

I use the following 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 并且还定义了空格折叠.

It defines a requiredStringType that must be at least one character long and also defines whitespace collapse.

当我验证以下 Xml 文档时,验证成功:

When I validate the following Xml document the validation succeedes:

<?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 定义了空白折叠:

w3.org defines for whitespace collapse:

在替换隐含的处理之后,#x20 的连续序列被折叠为单个 #x20,并且前导和尾随 #x20 被删除."

"After the processing implied by replace, contiguous sequences of #x20's are collapsed to a single #x20, and leading and trailing #x20's are removed."

这是否意味着将 3 个空格折叠为 1 个或零个空格?在 XmlSpy 中验证失败,在 .Net 中它成功.

Does this mean that 3 whitespaces are collapsed to one or to zero whitespaces? In XmlSpy the validation fails, in .Net it succeeds.

推荐答案

因为它说去除了前导和尾随空格,这意味着只包含空格的字符串将被折叠为空字符串.XmlSpy 在验证方面很准确,而 .NET 很慷慨(或正在犯错误).

Since it says that leading and trailing whitespace are removed, that means that a string that contains only whitespace will be collapsed to an empty string. XmlSpy is being accurate in the validation and .NET is being generous (or is making an error).

这是根据 验证期间的空白空间归一化来自XML 架构第 1 部分:结构第二版.

保留
没有做归一化,值为·归一化值·
替换
所有出现的 #x9(制表符)、#xA(换行)和 #xD(回车)都被替换为 > 为 #x20(空格).
崩溃
在上述替换下指定的替换之后,连续序列#x20s 折叠为单个 #x20,并删除初始和/或最终 #x20s.

preserve
No normalization is done, the value is the ·normalized value·
replace
All occurrences of #x9 (tab), #xA (line feed) and #xD (carriage return) are replaced > with #x20 (space).
collapse
Subsequent to the replacements specified above under replace, contiguous sequences of #x20s are collapsed to a single #x20, and initial and/or final #x20s are deleted.

因此,首先所有空格都被空白字符替换,第二个连续序列被单个空白字符替换,第三个和最后一个,初始和最后的空格被删除.按照此顺序,在验证期间必须将仅包含空格的字符串规范化为空字符串.

Thus, first all whitespace is replaced by blank characters, second contiguous sequences are replaced with a single blank character, third and last, initial and final blanks are deleted. Following this sequence, a string containing only whitespace must be normalized to an empty string during validation.

这篇关于XmlSchema 空白崩溃:多个空白会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆