xsd:boolean element type接受"true"但不接受"True".我怎么能让它接受呢?

Soi*_*shi 52 xml xsd boolean

我正在使用xmllint --schema选项来验证我看起来像这样的XML

<XML>
<Active>True</Active>
</XML>
Run Code Online (Sandbox Code Playgroud)

在我的模式文件中,我有以下描述Active元素的行.

<xsd:element name="Active" type="xs:boolean" />
Run Code Online (Sandbox Code Playgroud)

当我运行xmllint时,我会收到错误消息

/tmp/schema_validation.xml:73:element Active:架构有效性错误:元素'Active':'True'不是原子类型'xs:boolean'的有效值.

当我将XML更改为

<Active>true</Active>
Run Code Online (Sandbox Code Playgroud)

然后错误消息消失.

所以,它看起来像xsd:boolean意味着它全部小写为"true/false"而不是xmllint的"True/False".我的问题是,如何使xmllint接受xsd:boolean类型的"True"?或者我可以使用哪些工具来验证这个XML?此时更改XML或架构不是我的选择.

谢谢!

Che*_*eso 106

你不能.

根据XML Schema规范,布尔值是truefalse. True无效:


  3.2.2.1 Lexical representation
  An instance of a datatype that is defined as ·boolean· can have the 
  following legal literals {true, false, 1, 0}. 

  3.2.2.2 Canonical representation
  The canonical representation for boolean is the set of 
  literals {true, false}. 

如果您使用的工具真正验证了XML Schema标准,那么您无法说服它接受一个布尔值的True.

  • 谢谢.很高兴知道绝对没有办法重新定义xsd:boolean (6认同)
  • 我和@Oskar在这里会有所不同.有些工具声称可以生成XML,但实际上并没有,因为它们生成的内容并不是很好.但是在这里你似乎有上游软件生成的XML**格式良好,但根据其XML Schema无效.它仍然是XML.他们只是不能声称它符合您正在使用的XML Schema. (5认同)
  • 换句话说 - 如果上游软件为定义为XML Schema布尔值的东西生成True,那么它们实际上不会生成XML,而是恰好看起来类似的其他东西.他们的营销部门不应该声称他们使用XML,因为他们现在已经使使用XML无效 - 为了提高效率而重用常用解析器的能力. (2认同)
  • 实际上,1,0也是有效值。请参阅:https://www.w3schools.com/xml/schema_dtypes_misc.asp (2认同)

Pav*_*aev 50

xs:boolean是关于它接受什么样的输入预定义的.如果您需要不同的东西,则必须定义自己的枚举:

 <xs:simpleType name="my:boolean">
    <xs:restriction base="xs:string">
      <xs:enumeration value="True"/>
      <xs:enumeration value="False"/>
    </xs:restriction>
  </xs:simpleType>
Run Code Online (Sandbox Code Playgroud)