This section describes the built-in primitive datatype, 'decimal' that represents signed decimal numbers. Leading and trailing whitespaces are allowed and trimmed.
The "decimal" datatype and its derived datatypes are frequently used built-in datatypes
in XML documents. Let's take a closer look at the "decimal" datatype first.
"decimal" is a built-in primitive datatype designed to represent signed decimal numbers
with these rules:
The value space of "decimal" is all possible signed decimal numbers.
The lexical space of "decimal" is all possible signed decimal numbers represented in decimal format
with with leading and trailing whitespaces allowed and trimmed.
Leading zeroes before the decimal point and trailing zeros after the decimal point are optional.
A "decimal" lexical representation after whitespaces are trimmed should match this regular expression:
/(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)/.
To verify these rules, I wrote this simple XSD document that uses "decimal" datatype to declare XML elements:
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:
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
decimal_datatype_test.xsd decimal_datatype_test.xml
Error:
Line number: 15
Column number: 31
Message: cvc-datatype-valid.1.2.1: '+ 123.456' is not a valid value
for 'decimal'.
Error:
Line number: 15
Column number: 31
Message: cvc-type.3.1.3: The value '+ 123.456' of element 'Decimal'
is not valid.
Error:
Line number: 16
Column number: 32
Message: cvc-datatype-valid.1.2.1: '-1,234.456' is not a valid
value for 'decimal'.
Error:
Line number: 16
Column number: 32
Message: cvc-type.3.1.3: The value '-1,234.456' of element
'Decimal' is not valid.
Error:
Line number: 17
Column number: 30
Message: cvc-datatype-valid.1.2.1: '1.2345e2' is not a valid value
for 'decimal'.
Error:
Line number: 17
Column number: 30
Message: cvc-type.3.1.3: The value '1.2345e2' of element 'Decimal'
is not valid.
Failed with errors: 6