views:

1286

answers:

2

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="xsd: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!

+4  A: 

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.

Cheeso
Thanks. It's good to know that there is absolutely no way to redefine xsd:boolean
SoichiH
+3  A: 

xs:boolean is predefined with regard to what kind of input it accepts. If you need something different, you have to define your own enumeration:

 <xs:simpleType name="my:boolean">
    <xs:restriction base="xs:string">
      <xs:enumeration value="True"/>
      <xs:enumeration value="False"/>
    </xs:restriction>
  </xs:simpleType>
Pavel Minaev
Thanks! I will request something likee this to be part of the schema so that I can work around this for now.
SoichiH