XML Schema Tutorials - Herong's Tutorial Examples
∟XML Schema Built-in Datatypes
∟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:
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"> <xs:complexType> <!-- Using "maxInclusive" restriction facet --> <xs:attribute name="quantity"> <xs:simpleType> <xs:restriction base="xs:positiveInteger"> <xs:maxInclusive value="1000"/> </xs:restriction> </xs:simpleType> </xs:attribute> <!-- Using "totalDigits" and other restriction facets --> <xs:attribute name="price"> <xs:simpleType> <xs:restriction base="xs:decimal"> <xs:totalDigits value='5'/> <xs:fractionDigits value='2'/> <xs:minInclusive value='10.01'/> <xs:maxInclusive value='99.99'/> </xs:restriction> </xs:simpleType> </xs:attribute> <!-- Using "minInclusive" restriction facet --> <xs:attribute name="subTotal"> <xs:simpleType> <xs:restriction base="xs:decimal"> <xs:minInclusive value='10.01'/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:schema>
Here is a sample XML document, decimal_datatype.xml, that conforms to decimal_datatype.xsd:
<?xml version="1.0"?> <orderLine quantity="3" price="19.99" subTotal="59.97" />
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
Glossary
References
PDF Printing Version