XML 区分大小写吗?
简短问题
XML 区分大小写吗?
较长的问题
例如:
<Shirt color="Red"/>
属性颜色的类型为string
,可能包含一组有效颜色(Red
、Blue
)代码> 和<代码>绿色)。
为了验证 XML,我使用了以下 XSD:
<xs:simpleType name="ColorType">
<xs:restriction base="xs:string">
<xs:enumeration value="Red"/>
<xs:enumeration value="Blue"/>
<xs:enumeration value="Green"/>
</xs:restriction>
</xs:simpleType>
我期望接受红色、蓝色和绿色的不同大小写变体吗?或者 XML 被广泛接受为区分大小写?
Short question
Is XML case-sensitive?
Longer question
For example:
<Shirt color="Red"/>
The attribute color is of type string
that may contain a set of valid colors (Red
, Blue
and Green
).
To validate the XML, I used the following XSD:
<xs:simpleType name="ColorType">
<xs:restriction base="xs:string">
<xs:enumeration value="Red"/>
<xs:enumeration value="Blue"/>
<xs:enumeration value="Green"/>
</xs:restriction>
</xs:simpleType>
Am I expected to accept different case variations of Red, Blue and Green? Or XML is widely accepted as case-sensitive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短回答:
是的 - XML 区分大小写。
更长的答案:
它被广泛接受为区分大小写,但是如果您想更灵活地接受,请查看下面的问题,其中讨论了不区分大小写的枚举:
简单类型字符串的 XML 模式不区分大小写枚举
Short Answer:
Yes - XML is case sensitive.
Longer Answer:
It is widely accepted as case sensitive, however if you want to accept more flexibly, take a look at the question below, which discusses having case-insensitive enumerations:
XML Schema Case Insensitive Enumeration of Simple Type String
使用 XSD 1.1,您可以使用断言实现不区分大小写的枚举:
最近版本的 Saxon 和 Xerces 支持 XSD 1.1。
With XSD 1.1 you can achieve a case-insensitive enumeration using an assertion:
XSD 1.1 is supported in recent releases of Saxon and Xerces.
是的。检查当前 XML 规范,唯一明显的声明是在第 1.2 节中,其中作者指出:
请注意,缺少大小写折叠。作为不注意这一细节可能导致的麻烦的一个例子,我最近分析了一些代码,该代码从中等大小(几个 100 GB)的生理数据语料库中提取数据,其中一个参数名称已从 SPO2 更改为 SpO2经过多年的发展,在主要软件中。
相比之下,用于提取数据的软件忠实地保留了 XML 约定,并将参数视为不同的。更糟糕的事情还在后面。因为参数名称用于命名写入数据的 CSV 文件,而这是在 Windows 中,它会大小写折叠其文件名,所以在同一个文件上打开两个句柄,从而导致神秘错误。
Yes. Examining the current XML specification, the only apparent statement of this is in Section 1.2, where the authors state:
Note the reference to a lack of case folding. As an example of the trouble that inattention to this detail can cause, I recently analysed some code that extracts data from a moderate-sized (a few 100 GB) corpus of physiological data where one parameter name had been changed from SPO2 to SpO2 over the course of years, within the primary software.
In contrast, the software used to extract the data faithfully preserved the XML convention and saw the parameters as distinct. There was worse to come. Because the parameter name was used to name the CSV file to which data were written, and this was in Windows, which case-folds its filenames, two handles were being opened on the same file, resulting in mysterious errors.