XML 是否区分大小写?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7414747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 14:57:12  来源:igfitidea点击:

Is XML case-sensitive?

xmlcase-sensitive

提问by Ian

Short question

简短的问题

Is XML case-sensitive?

XML 是否区分大小写?

Longer question

更长的问题

For example:

例如:

<Shirt color="Red"/>

The attribute color is of type stringthat may contain a set of valid colors (Red, Blueand Green).

属性颜色的类型string可能包含一组有效颜色(RedBlueGreen)。

To validate the XML, I used the following XSD:

为了验证 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>

Am I expectedto accept different case variations of Red, Blue and Green? Or XML is widely accepted as case-sensitive?

我是否应该接受红色、蓝色和绿色的不同大小写变化?或者 XML 被广泛接受为区分大小写?

采纳答案by Jon Egerton

Short Answer:

简答:

Yes - XML is case sensitive.

是 - XML 区分大小写。

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

简单类型字符串的 XML 模式不区分大小写枚举

回答by Michael Kay

With XSD 1.1 you can achieve a case-insensitive enumeration using an assertion:

使用 XSD 1.1,您可以使用断言实现不区分大小写的枚举:

<xs:simpleType name="RGB">
  <xs:restriction base="xs:string">
    <xs:assert test="lower-case($value) = ('red', 'green', 'blue')"/>
  </xs:restriction>
</xs:simpleType>

XSD 1.1 is supported in recent releases of Saxon and Xerces.

最近版本的 Saxon 和 Xerces 支持 XSD 1.1。