XML Schema Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.11

Built-in Datatype - "decimal"

This section describes what is built-in datatype decimal and its restriction facets.

The built-in datatype "decimal" is also used often in XML documents. It represents decimal values like, -1.23, 12678967.543233, +100000.00, 210.

There are several built-in datatypes derived from "decimal" like, "integer", "long", "int", "short", "byte", etc.

"decimal" and its derived datatypes support the following constraining facets:

  • totalDigits - Specifies Controls the maximum number of values in the value space of datatypes derived from decimal.
  • fractionDigits - fractionDigits controls the size of the minimum difference between values in the value space of datatypes derived from decimal.
  • pattern - Specifies a pattern for the string datatype.
  • enumeration - Specifies a list of string values for the string datatype.
  • whiteSpace - Specifies how white spaces to be handled based on 3 options: "preserve", "replace", or "collapse".
  • maxInclusive - Specifies the maximum value inclusively.
  • maxExclusive - Specifies the maximum value exclusively.
  • minInclusive - Specifies the minimum value inclusively.
  • minExclusive - Specifies the minimum value exclusively.

Here is a sample schema, decimal_datatype.xsd, that uses "decimal" and other numeric built-in datatypes with different restriction facets:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- decimal_datatype.xsd
 - Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.

 <xs:element name="orderLine">

   <!-- Using "maxInclusive" restriction facet -->
   <xs:attribute name="quantity">
     <xs:restriction base="xs:positiveInteger">
      <xs:maxInclusive value="1000"/>

   <!-- Using "totalDigits" and other restriction facets -->
   <xs:attribute name="price">
     <xs:restriction base="xs:decimal">
      <xs:totalDigits value='5'/>
      <xs:fractionDigits value='2'/>
      <xs:minInclusive value='10.01'/>
      <xs:maxInclusive value='99.99'/>

   <!-- Using "minInclusive" restriction facet -->
   <xs:attribute name="subTotal">
     <xs:restriction base="xs:decimal">
      <xs:minInclusive value='10.01'/>




Here is a sample XML document, decimal_datatype.xml, that conforms to decimal_datatype.xsd:

<?xml version="1.0"?>

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

 XML Parser API - Xerces2 Java Parser

 XML Schema Language - Basics

XML Schema Built-in Datatypes

 Overview of XML Schema Built-in Datatypes

 List of Built-in Datatypes

 Deriving from Built-in Datatypes - simpleType

 Built-in Datatype - "string"

 Built-in Datatype - "string" Errors

 Built-in Datatype - "dateTime"

 Built-in Datatype - "dateTime" Errors

Built-in Datatype - "decimal"

 Built-in Datatype - "decimal" Errors

 Complex Element Declaration

 XML Schema Location and Namespace in XML Documents

 Overriding Element Types in XML Documents

 Linking Multiple Schema Documents Together



 PDF Printing Version

Dr. Herong Yang, updated in 2009
Built-in Datatype - "decimal"