XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
"boolean" Datatype Values and Representations
This section describes the built-in primitive datatype, 'boolean' that represents 2 Boolean values of true and false. Whitespaces are allowed and removed.
"boolean" is probably the most simplest built-in datatype supported in XSD 1.1. Here is how it is defined:
To verify these rules, I wrote this simple XSD document that uses "boolean" datatype to declare XML elements:
<?xml version="1.1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- boolean_datatype_test.xsd - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <xs:element name="Boolean_Datatype_Test"> <xs:complexType> <xs:sequence> <xs:element name="Boolean" type="xs:boolean" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Here is a sample XML document that can be used to test these declarations:
<?xml version="1.1"?> <!-- boolean_datatype_test.xml - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <Boolean_Datatype_Test> <!-- 4 valid "Boolean" elements --> <Boolean> true </Boolean> <Boolean> 1 </Boolean> <Boolean> false </Boolean> <Boolean> 0 </Boolean> <!-- 3 invalid "Boolean" elements --> <Boolean> True </Boolean> <Boolean> FALSE </Boolean> <Boolean> 1=1 </Boolean> </Boolean_Datatype_Test>
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book, I get 6 groups of errors for 6 invalid XML elements:
herong> java XsdSchemaValidator ^^^ boolean_datatype_test.xsd boolean_datatype_test.xml Error: Line number: 14 Column number: 33 Message: cvc-datatype-valid.1.2.1: 'True' is not a valid value for 'boolean'. (Must all lower cases) Error: Line number: 14 Column number: 33 Message: cvc-type.3.1.3: The value ' True ' of element 'Boolean' is not valid. Error: Line number: 15 Column number: 34 Message: cvc-datatype-valid.1.2.1: 'FALSE' is not a valid value for 'boolean'. (Must all lower cases) Error: Line number: 15 Column number: 34 Message: cvc-type.3.1.3: The value ' FALSE ' of element 'Boolean' is not valid. Error: Line number: 16 Column number: 31 Message: cvc-datatype-valid.1.2.1: '1=1' is not a valid value for 'boolean'. (Not a valid representation) Error: Line number: 16 Column number: 31 Message: cvc-type.3.1.3: The value ' 1=1 ' of element 'Boolean' is not valid. Failed with errors: 6
Table of Contents
XML Editor and Schema Processor - XMLPad
Java API for XML Processing - JAXP
JAXP - XML Schema (XSD) Validation
Xerces2 Java Parser - Java API of XML Parsers
Introduction of XSD Built-in Datatypes
"string" and Its Derived Datatypes
"decimal" and Its Derived Datatypes
"dateTime" and Its Related Datatypes
►Miscellaneous Built-in Datatypes
"anyURI" Datatype Values and Representations
"QName" Datatype Values and Representations
"NOTATION" Datatype Values and Representations
"base64Binary" Datatype Values and Representations
"hexBinary" Datatype Values and Representations
"float" and "double" Datatype Values and Representations
►"boolean" Datatype Values and Representations
Facets, Constraining Facets and Restriction Datatypes
"simpleType" - Defining Your Own Simple Datatypes
Identity-Constraints: unique, key and keyref
Assertion as Custom Validation Rules
XML Schema Location and Namespace in XML Documents
Overriding Element Types in XML Documents