xsd:boolean 元素类型接受“true";但不是“真".我怎样才能让它接受它? [英] xsd:boolean element type accept "true" but not "True". How can I make it accept it?

查看:21
本文介绍了xsd:boolean 元素类型接受“true";但不是“真".我怎样才能让它接受它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<XML><主动>真</主动></XML>

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

<xsd:element name="Active" type="xs:boolean"/>

当我运行 xmllint 时,我收到错误消息,上面写着

<块引用>

/tmp/schema_validation.xml:73: 元素活动:模式有效性错误:元素活动":真"不是原子类型的有效值'xs:boolean'.

当我将 XML 更改为

<Active>true</Active>

然后错误信息消失.

所以,看起来 xsd:boolean 对 xmllint 来说都是小写的真/假",但不是真/假".我的问题是,我怎样才能让 xmllint 接受 xsd:boolean 类型的真"?或者我可以使用不同的工具来验证这个 XML?在这一点上,更改 XML 或架构不是我的选择.

谢谢!

解决方案

你不能.

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

<上一页>3.2.2.1 词法表示定义为·boolean· 的数据类型的实例可以具有遵循合法文字 {true, false, 1, 0}.3.2.2.2 规范表示布尔值的规范表示是字面量 {true, false}.

如果您使用的工具确实根据 XML Schema 标准进行验证,那么您无法说服它接受 True 作为布尔值.

I am using xmllint --schema option to validate my XML that looks like this

<XML>
<Active>True</Active>
</XML>

In my schema file, I have following line that describes Active element.

<xsd:element name="Active" type="xs:boolean" />

When I run xmllint, I get error messages that says

/tmp/schema_validation.xml:73: element Active: Schemas validity error : Element 'Active': 'True' is not a valid value of the atomic type 'xs:boolean'.

When I change the XML to

<Active>true</Active>

Then the error message disappears.

So, it looks like xsd:boolean means it's all lowercase "true/false" but not "True/False" to xmllint.. My question is, how can I make xmllint to accept "True" for xsd:boolean type? Or is there different tools that I can use that will validate this XML? Changing the XML or schema is not my option at this point.

Thanks!

解决方案

You cannot.

According to the XML Schema specification, a boolean is true or false. True is not valid:


  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}. 

If the tool you are using truly validates against the XML Schema standard, then you cannot convince it to accept True for a boolean.

这篇关于xsd:boolean 元素类型接受“true";但不是“真".我怎样才能让它接受它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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