This section describes the built-in primitive datatypes, 'nonNegativeInteger', 'positiveInteger', 'nonPositiveInteger' and 'negativeInteger', that represents integer numbers according signs and the zero value. Leading and trailing whitespaces are allowed and trimmed.
Also based on the "long" datatype, 4 other built-in datatypes are derived in XSD 1.1 to
represent integer numbers within different ranges according to signs and the zero value:
"nonNegativeInteger", "positiveInteger", "nonPositiveInteger" and "negativeInteger".
Their definitions can be summarized as:
The value space of "nonNegativeInteger" is all positive integer numbers and zero. Negative integers are excluded.
The value space of "positiveInteger" is all positive integer numbers. Zero and negative integers are excluded.
The value space of "nonPositiveInteger" is all negative integer numbers and zero. Positive integers are excluded.
The value space of "negativeInteger" is all negative integer numbers. Zero and positive integers are excluded.
Lexical spaces of "nonNegativeInteger", "positiveInteger", "nonPositiveInteger" and "negativeInteger"
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.
"nonNegativeInteger", "positiveInteger", "nonPositiveInteger" and "negativeInteger"
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 "nonNegativeInteger", "positiveInteger",
"nonPositiveInteger" and "negativeInteger" datatypes to declare XML elements:
Here is a sample XML document that can be used to test these declarations:
<?xml version="1.1"?>
<!-- positive_negative_integer_datatype_test.xml
- Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<Positive_Negative_Integer_Datatype_Test>
<!-- 2 valid "NonNegativeInteger" elements -->
<NonNegativeInteger>012345678901234567890123456</NonNegativeInteger>
<NonNegativeInteger>000000000000000000000000000</NonNegativeInteger>
<!-- 1 invalid "NonNegativeInteger" elements -->
<NonNegativeInteger>-1</NonNegativeInteger>
<!-- 1 valid "PositiveInteger" elements -->
<PositiveInteger>012345678901234567890123456</PositiveInteger>
<!-- 2 invalid "PositiveInteger" elements -->
<PositiveInteger>-1</PositiveInteger>
<PositiveInteger> 0</PositiveInteger>
<!-- 2 valid "NonPositiveInteger" elements -->
<NonPositiveInteger>-012345678901234567890123456</NonPositiveInteger>
<NonPositiveInteger> 000000000000000000000000000</NonPositiveInteger>
<!-- 1 invalid "NonPositiveInteger" elements -->
<NonPositiveInteger>1</NonPositiveInteger>
<!-- 1 valid "NegativeInteger" elements -->
<NegativeInteger>-012345678901234567890123456</NegativeInteger>
<!-- 2 invalid "NegativeInteger" elements -->
<NegativeInteger>1</NegativeInteger>
<NegativeInteger>0</NegativeInteger>
</Positive_Negative_Integer_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
positive_negative_integer_datatype_test.xsd
positive_negative_integer_datatype_test.xml
Error:
Line number: 11
Column number: 46
Message: cvc-minInclusive-valid: Value '-1' is not facet-valid with
respect to minInclusive '0' for type 'nonNegativeInteger'.
Error:
Line number: 11
Column number: 46
Message: cvc-type.3.1.3: The value '-1' of element
'NonNegativeInteger' is not valid.
Error:
Line number: 17
Column number: 40
Message: cvc-minInclusive-valid: Value '-1' is not facet-valid with
respect to minInclusive '1' for type 'positiveInteger'.
Error:
Line number: 17
Column number: 40
Message: cvc-type.3.1.3: The value '-1' of element
'PositiveInteger' is not valid.
Error:
Line number: 18
Column number: 40
Message: cvc-minInclusive-valid: Value '0' is not facet-valid with
respect to minInclusive '1' for type 'positiveInteger'.
Error:
Line number: 18
Column number: 40
Message: cvc-type.3.1.3: The value ' 0' of element
'PositiveInteger' is not valid.
Error:
Line number: 25
Column number: 45
Message: cvc-maxInclusive-valid: Value '1' is not facet-valid with
respect to maxInclusive '0' for type 'nonPositiveInteger'.
Error:
Line number: 25
Column number: 45
Message: cvc-type.3.1.3: The value '1' of element
'NonPositiveInteger' is not valid.
Error:
Line number: 31
Column number: 39
Message: cvc-maxInclusive-valid: Value '1' is not facet-valid with
respect to maxInclusive '-1' for type 'negativeInteger'.
Error:
Line number: 31
Column number: 39
Message: cvc-type.3.1.3: The value '1' of element 'NegativeInteger'
is not valid.
Error:
Line number: 32
Column number: 39
Message: cvc-maxInclusive-valid: Value '0' is not facet-valid with
respect to maxInclusive '-1' for type 'negativeInteger'.
Error:
Line number: 32
Column number: 39
Message: cvc-type.3.1.3: The value '0' of element 'NegativeInteger'
is not valid.
Failed with errors: 12