XSD Tutorials - Herong's Tutorial Examples - Version 5.10, by Dr. Herong Yang

"integer" Datatype Values and Representations

This section describes the built-in primitive datatype, 'integer' that represents signed integer numbers. Leading and trailing whitespaces are allowed and trimmed.

Based on what we have learned on "decimal" datatype in the previous section, let's now look at its first derived datatype: integer.

"integer" is a built-in datatype derived from "decimal" datatype to represent signed integer numbers with these rules:

  • The value space of "integer" is all possible signed integer numbers.
  • The lexical space of "integer" is all possible signed integer numbers represented in decimal format with with leading and trailing whitespaces allowed and trimmed.
  • Leading zeroes are optional.
  • Decimal point is not allowed.
  • A "integer" lexical representation after whitespaces are trimmed should match this regular expression: /[\-+]?[0-9]+/.

To verify these rules, I wrote this simple XSD document that uses "integer" datatype to declare XML elements:

<?xml version="1.1"?>
<!-- integer_datatype_test.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Integer_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Integer" type="xs:integer" 
        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"?>
<!-- integer_datatype_test.xml
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<Integer_Datatype_Test>
<!-- 4 valid "Integer" elements -->
  <Integer>  +123456   </Integer>
  <Integer>     -1234456  </Integer>
  <Integer>   00000001234560000000 </Integer>
  <Integer> 
    012345678901234567890123456789012345678901234567890123456789 
  </Integer>

<!-- 3 invalid "Integer" elements -->
  <Integer>+ 123456</Integer>
  <Integer>-1,234,456</Integer>
  <Integer>12345.</Integer>
</Integer_Datatype_Test>

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 
   integer_datatype_test.xsd integer_datatype_test.xml
   
Error:
   Line number: 15
   Column number: 30
   Message: cvc-datatype-valid.1.2.1: '+ 123456' is not a valid value
   for 'integer'.

Error:
   Line number: 15
   Column number: 30
   Message: cvc-type.3.1.3: The value '+ 123456' of element 'Integer'
   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 'integer'.

Error:
   Line number: 16
   Column number: 32
   Message: cvc-type.3.1.3: The value '-1,234,456' of element 
   'Integer' is not valid.

Error:
   Line number: 17
   Column number: 28
   Message: cvc-datatype-valid.1.2.1: '12345.' is not a valid value
   for 'integer'.

Error:
   Line number: 17
   Column number: 28
   Message: cvc-type.3.1.3: The value '12345.' of element 'Integer'
   is not valid.
   
Failed with errors: 6

Last update: 2013.

Table of Contents

 About This Book

 Introduction to XML Schema

 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

 Using Xerces2 Java API

 XML Schema Language - Basics

 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

 Complex Element Declaration

 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

 Linking Multiple Schema Documents Together

 Glossary

 References

 PDF Printing Version

"integer" Datatype Values and Representations - Updated in 2014, by Dr. Herong Yang