XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
"long", "int", "short" and "byte" Datatypes
This section describes the built-in primitive datatypes, 'long', 'int', 'short' and 'byte', that represents signed integer numbers for different storage sizes. Leading and trailing whitespaces are allowed and trimmed.
Based on the "integer" datatype, 4 other built-in datatypes are derived in XSD 1.1 to represent signed integer numbers within different storage sizes: "long", "int", "short" and "byte". Their definitions can be summarized as:
To verify these rules, I wrote this simple XSD document that uses "long", "int", "short" and "byte" datatypes to declare XML elements:
<?xml version="1.1"?> <!-- long_int_short_byte_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="Long_Int_Short_Byte_Datatype_Test"> <xs:complexType> <xs:sequence> <xs:element name="Long" type="xs:long" maxOccurs="unbounded"/> <xs:element name="Int" type="xs:int" maxOccurs="unbounded"/> <xs:element name="Short" type="xs:short" maxOccurs="unbounded"/> <xs:element name="Byte" type="xs:byte" 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"?> <!-- long_int_short_byte_datatype_test.xml - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <Long_Int_Short_Byte_Datatype_Test> <!-- 2 valid "Long" elements --> <Long> -9223372036854775808 </Long> <Long> 09223372036854775807 </Long> <!-- 2 invalid "Long" elements --> <Long>-9223372036854775809</Long> <Long> 9223372036854775808</Long> <!-- 2 valid "Int" elements --> <Int> -2147483648 </Int> <Int> 02147483647 </Int> <!-- 2 invalid "Int" elements --> <Int> -2147483649 </Int> <Int> 2147483648 </Int> <!-- 2 valid "Short" elements --> <Short> -32768 </Short> <Short> 032767 </Short> <!-- 2 invalid "Short" elements --> <Short> -32769 </Short> <Short> 32768 </Short> <!-- 2 valid "Byte" elements --> <Byte> -128 </Byte> <Byte> 0127 </Byte> <!-- 2 invalid "Byte" elements --> <Byte> -129 </Byte> <Byte> 128 </Byte> </Long_Int_Short_Byte_Datatype_Test>
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book, I get 8 groups of errors for 8 invalid XML elements:
herong> java XsdSchemaValidator ^^^ long_int_short_byte_datatype_test.xsd ^^^ long_int_short_byte_datatype_test.xml Error: Line number: 11 Column number: 36 Message: cvc-minInclusive-valid: Value '-9223372036854775809' is not facet-valid with respect to minInclusive '-9223372036854775808' for type 'long'. Error: Line number: 11 Column number: 36 Message: cvc-type.3.1.3: The value '-9223372036854775809' of element 'Long' is not valid. Error: Line number: 12 Column number: 36 Message: cvc-maxInclusive-valid: Value '9223372036854775808' is not facet-valid with respect to maxInclusive '9223372036854775807' for type 'long'. Error: Line number: 12 Column number: 36 Message: cvc-type.3.1.3: The value ' 9223372036854775808' of element 'Long' is not valid. Error: Line number: 19 Column number: 30 Message: cvc-minInclusive-valid: Value '-2147483649' is not facet- valid with respect to minInclusive '-2147483648' for type 'int'. Error: Line number: 19 Column number: 30 Message: cvc-type.3.1.3: The value ' -2147483649 ' of element 'Int' is not valid. Error: Line number: 20 Column number: 30 Message: cvc-maxInclusive-valid: Value '2147483648' is not facet -valid with respect to maxInclusive '2147483647' for type 'int'. Error: Line number: 20 Column number: 30 Message: cvc-type.3.1.3: The value ' 2147483648 ' of element 'Int' is not valid. Error: Line number: 27 Column number: 29 Message: cvc-minInclusive-valid: Value '-32769' is not facet-valid with respect to minInclusive '-32768' for type 'short'. Error: Line number: 27 Column number: 29 Message: cvc-type.3.1.3: The value ' -32769 ' of element 'Short' is not valid. Error: Line number: 28 Column number: 29 Message: cvc-maxInclusive-valid: Value '32768' is not facet-valid with respect to maxInclusive '32767' for type 'short'. Error: Line number: 28 Column number: 29 Message: cvc-type.3.1.3: The value ' 32768 ' of element 'Short' is not valid. Error: Line number: 35 Column number: 25 Message: cvc-minInclusive-valid: Value '-129' is not facet-valid with respect to minInclusive '-128' for type 'byte'. Error: Line number: 35 Column number: 25 Message: cvc-type.3.1.3: The value ' -129 ' of element 'Byte' is not valid. Error: Line number: 36 Column number: 25 Message: cvc-maxInclusive-valid: Value '128' is not facet-valid with respect to maxInclusive '127' for type 'byte'. Error: Line number: 36 Column number: 25 Message: cvc-type.3.1.3: The value ' 128 ' of element 'Byte' 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