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:
The value space of "unsignedLong" is all unsigned integer numbers that can be stored in a 64-bit storage.
"unsignedLong" values are in the range of 0 and 18446744073709551615.
The value space of "unsignedInt" is all unsigned integer numbers that can be stored in a 32-bit storage.
"unsignedLong" values are in the range of 0 and 4294967295.
The value space of "unsignedShort" is all unsigned integer numbers that can be stored in a 16-bit storage.
"unsignedLong" values are in the range of 0 and 65535.
The value space of "unsignedByte" is all unsigned integer numbers that can be stored in a 8-bit storage.
"unsignedLong" values are in the range of 0 and 255.
Lexical spaces of "unsignedLong", "unsignedInt", "unsignedShort" and "unsignedByte"
are all possible values in their value spaces represented in decimal format
with leading and trailing whitespaces allowed and trimmed.
Leading zeroes are optional.
Decimal point is not allowed.
"unsignedLong", "unsignedInt", "unsignedShort" and "unsignedByte"
lexical representations after whitespaces are trimmed should match this regular expression:
/[\-+]?[0-9]+/.
To verify these rules, I wrote this simple XSD document that uses
"unsignedLong", "unsignedInt", "unsignedShort" and "unsignedByte" datatypes to declare XML elements:
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) 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:
c:\Progra~1\Java\jdk1.7.0_07\bin\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