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!
Syntax of XML boolean xml version="1.0" encoding="utf-8"?> Following is a boolean declaration in schemas. The value of a boolean is an Integer value whose values are '0' and '1', representing logical yes or no.
The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.
An XML schema definition (XSD), is a framework document that defines the rules and constraints for XML documents. An XSD formally describes the elements in an XML document and can be used to validate the contents of the XML document to make sure that it adheres to the rules of the XSD.
xsd:anyType is a type, like xsd:integer (though xsd:anyType is special in that it can act as a simple or complex type, and it places essentially no restrictions on the tree that it validates -- think of it loosely as the Schema language's analog of java. lang. Object).
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}.
The value space of xs:boolean is “true” and “false,” and its lexical space accepts true, false, and also “1” (for true) and “0” (for false). This datatype cannot be localized—for instance, to accept “vrai” and “faux” instead of “true” and “false”. Get XML Schema now with the O’Reilly learning platform.
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?
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}.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With