我正在使用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规范,布尔值是true或false. 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.
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)
| 归档时间: |
|
| 查看次数: |
121114 次 |
| 最近记录: |