XSD Tutorials - Herong's Tutorial Examples - v5.22, by Herong Yang
"hexBinary" Datatype Values and Representations
This section describes the built-in primitive datatype, 'hexBinary' that represents binary data represented in hexadecimal encoding. Leading and trailing whitespaces allowed and trimmed.
"hexBinary" is a built-in datatype that represents binary data encoded in hexadecimal format with these rules:
To verify these rules, I wrote this simple XSD document that uses "hexBinary" datatype to declare XML elements:
<?xml version="1.1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- hexBinary_datatype_test.xsd - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <xs:element name="HexBinary_Datatype_Test"> <xs:complexType> <xs:sequence> <xs:element name="HexBinary" type="xs:hexBinary" 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"?> <!-- hexBinary_datatype_test.xml - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <HexBinary_Datatype_Test> <!-- 3 valid "HexBinary" elements --> <HexBinary> 41 </HexBinary> <HexBinary> 6865726F6E6779616E672E636F6D </HexBinary> <HexBinary> 6865726f6e6779616e672e636f6d </HexBinary> <!-- 3 invalid "HexBinary" elements --> <HexBinary> 123 </HexBinary> <HexBinary> 4i </HexBinary> <HexBinary> 6865726F6E67 79616E672E636F6D </HexBinary> </HexBinary_Datatype_Test>
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book, I get 3 groups of errors for 3 invalid XML elements:
herong> java XsdSchemaValidator ^^^ hexBinary_datatype_test.xsd hexBinary_datatype_test.xml Error: Line number: 13 Column number: 36 Message: cvc-datatype-valid.1.2.1: '123' is not a valid value for 'hexBinary'. (Must be multiples of 2 characters) Error: Line number: 13 Column number: 36 Message: cvc-type.3.1.3: The value ' 123 ' of element 'HexBinary' is not valid. Error: Line number: 14 Column number: 35 Message: cvc-datatype-valid.1.2.1: '4i' is not a valid value for 'hexBinary'. ("i" is not allowed) Error: Line number: 14 Column number: 35 Message: cvc-type.3.1.3: The value ' 4i ' of element 'HexBinary' is not valid. Error: Line number: 15 Column number: 62 Message: cvc-datatype-valid.1.2.1: '6865726F6E67 79616E672E636F6D' is not a valid value for 'hexBinary'. (Whitespace is not allowed) Error: Line number: 15 Column number: 62 Message: cvc-type.3.1.3: The value ' 6865726F6E67 79616E672E636F6D ' of element 'HexBinary' 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