XSD Tutorials - Herong's Tutorial Examples - v5.22, by Herong Yang
""unsignedLong" and "unsignedShort" Datatypes
This section describes the built-in primitive datatypes, 'unsignedLong', 'unsignedInt', 'unsignedShort' and 'unsignedByte', that represents unsigned integer numbers for different storage sizes. Leading and trailing whitespaces are allowed and trimmed.
Based on the "nonNegativeInteger" datatype, 4 other built-in datatypes are derived in XSD 1.1 to represent unsigned integer numbers for different storage spaces: "unsignedLong", "unsignedInt", "unsignedShort" and "unsignedByte". Their definitions can be summarized as:
To verify these rules, I wrote this simple XSD document that uses "unsignedLong", "unsignedInt", "unsignedShort" and "unsignedByte" datatypes to declare XML elements:
<?xml version="1.1"?> <!-- unsigedLong_unsignedShort_datatype_test.xsd - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="UnsignedLong_UnsignedShort_Datatype_Test"> <xs:complexType> <xs:sequence> <xs:element name="UnsignedLong" type="xs:unsignedLong" maxOccurs="unbounded"/> <xs:element name="UnsignedInt" type="xs:unsignedInt" maxOccurs="unbounded"/> <xs:element name="UnsignedShort" type="xs:unsignedShort" maxOccurs="unbounded"/> <xs:element name="UnsignedByte" type="xs:unsignedByte" 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"?> <!-- unsigedLong_unsignedShort_datatype_test.xml - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <UnsignedLong_UnsignedShort_Datatype_Test> <!-- 2 valid "UnsignedLong" elements --> <UnsignedLong>18446744073709551615</UnsignedLong> <UnsignedLong>000000000000000000000000000</UnsignedLong> <!-- 2 invalid "UnsignedLong" elements --> <UnsignedLong>18446744073709551616</UnsignedLong> <UnsignedLong>-1</UnsignedLong> <!-- 2 valid "UnsignedInt" elements --> <UnsignedInt>4294967295</UnsignedInt> <UnsignedInt>000000000000000000000000000</UnsignedInt> <!-- 2 invalid "UnsignedInt" elements --> <UnsignedInt>4294967296</UnsignedInt> <UnsignedInt>-1</UnsignedInt> <!-- 2 valid "UnsignedShort" elements --> <UnsignedShort>65535</UnsignedShort> <UnsignedShort>000000000000000000000000000</UnsignedShort> <!-- 2 invalid "UnsignedShort" elements --> <UnsignedShort>65536</UnsignedShort> <UnsignedShort>-1</UnsignedShort> <!-- 2 valid "UnsignedByte" elements --> <UnsignedByte>255</UnsignedByte> <UnsignedByte>000000000000000000000000000</UnsignedByte> <!-- 2 invalid "UnsignedByte" elements --> <UnsignedByte>256</UnsignedByte> <UnsignedByte>-1</UnsignedByte> </UnsignedLong_UnsignedShort_Datatype_Test>
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book, I get 6 groups errors for 6 invalid XML elements:
herong> java XsdSchemaValidator ^^^ unsigedLong_unsignedShort_datatype_test.xsd ^^^ unsigedLong_unsignedShort_datatype_test.xml Error: Line number: 11 Column number: 52 Message: cvc-maxInclusive-valid: Value '18446744073709551616' is not facet-valid with respect to maxInclusive '18446744073709551615' for type 'unsignedLong'. Error: Line number: 11 Column number: 52 Message: cvc-type.3.1.3: The value '18446744073709551616' of element 'UnsignedLong' is not valid. Error: Line number: 12 Column number: 34 Message: cvc-minInclusive-valid: Value '-1' is not facet-valid with respect to minInclusive '0' for type 'unsignedLong'. Error: Line number: 12 Column number: 34 Message: cvc-type.3.1.3: The value '-1' of element 'UnsignedLong' is not valid. Error: Line number: 19 Column number: 40 Message: cvc-maxInclusive-valid: Value '4294967296' is not facet- valid with respect to maxInclusive '4294967295' for type 'unsignedInt'. Error: Line number: 19 Column number: 40 Message: cvc-type.3.1.3: The value '4294967296' of element 'UnsignedInt' is not valid. Error: Line number: 20 Column number: 32 Message: cvc-minInclusive-valid: Value '-1' is not facet-valid with respect to minInclusive '0' for type 'unsignedInt'. Error: Line number: 20 Column number: 32 Message: cvc-type.3.1.3: The value '-1' of element 'UnsignedInt' is not valid. Error: Line number: 27 Column number: 39 Message: cvc-maxInclusive-valid: Value '65536' is not facet-valid with respect to maxInclusive '65535' for type 'unsignedShort'. Error: Line number: 27 Column number: 39 Message: cvc-type.3.1.3: The value '65536' of element 'UnsignedShort' is notvalid. Error: Line number: 28 Column number: 36 Message: cvc-minInclusive-valid: Value '-1' is not facet-valid with respect to minInclusive '0' for type 'unsignedShort'. Error: Line number: 28 Column number: 36 Message: cvc-type.3.1.3: The value '-1' of element 'UnsignedShort' is not valid. Error: Line number: 35 Column number: 35 Message: cvc-maxInclusive-valid: Value '256' is not facet-valid with respect to maxInclusive '255' for type 'unsignedByte'. Error: Line number: 35 Column number: 35 Message: cvc-type.3.1.3: The value '256' of element 'UnsignedByte' is not valid. Error: Line number: 36 Column number: 34 Message: cvc-minInclusive-valid: Value '-1' is not facet-valid with respect to minInclusive '0' for type 'unsignedByte'. Error: Line number: 36 Column number: 34 Message: cvc-type.3.1.3: The value '-1' of element 'UnsignedByte' is not valid. Failed with errors: 16
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
"decimal" Datatype Values and Representations
"integer" Datatype Values and Representations
"long", "int", "short" and "byte" Datatypes
"nonNegativeInteger", "positiveInteger", "nonPositiveInteger", "negativeInteger" Datatypes
►""unsignedLong" and "unsignedShort" Datatypes
"dateTime" and Its Related Datatypes
Miscellaneous Built-in Datatypes
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