Datatypes, Values and Representations

This section describes how built-in datatypes can be used to add type declarations to XML elements and attributes to help XML receiver to parse out desired values from XML documents.

There are 2 main purposes for providing XSD built-in datatypes:

In this section, we will concentrate on declare an XML element or an XML attribute with a built-in datatype. Building new custom datatypes based on built-in datatypes will be discussed in details in later sections.

First let's see an XML example without any datatype declaration:


When the receiver process this XML element, he/she will face a problem, because the content could be evaluated in multiple ways: as an integer value of 7,065,616,365; as a phone number of (706) 561-6365; and as an ASCII string of "peace".

The above problem can be resolved, if the "data" element were declared a built-in datatype, because each built-in datatype provided precise rules on:

To understand how built-in datatypes and their associated rules work, we need to introduce some terminologies:

With these terminologies, we can describe how XSD datatype can be used in processes of generating and processing XML documents as:

1. A user, the XML generator, has a value V he wants to communicate in an XML element E.

2. The XML generator finds that value V is in the value space of built-in datatype T.

3. The XML generator declares element E to be datatype T in the XSD document:

<xs:element name="E" type="xs:T"/>

4. The XML generator represents value V with a lexical representation R base on lexical space rules associated with datatype T and put it in element E in a XML document:


5. Another user, the XML receiver, receives the XSD document and the XML document.

6. The XML receiver parses the representation R based on lexical space rules associated with datatype T and retrieves the value V back.

The following diagram provides an illustration of how element E, datatype T, value V and representation R are related to each:
Datatype, Element, Value, Representation

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

 Overview of XSD 1.1 Built-in Datatypes

 List of Built-in Datatypes

Datatypes, Values and Representations

 Datatypes, Values and Representations - Example

 Built-in Datatypes Lexical Representation Examples

 Declaring Elements and Attributes with Built-in Datatypes

 Defining New Datatypes with Built-in Datatypes

 "anyType" Built-in Datatype Values and Representations

 "anySimpleType" Built-in Datatype Values and Representations

 "anyAtomicType" Built-in Datatype Values and Representations

 "string" and Its Derived Datatypes

 "decimal" and Its Derived 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



 PDF Printing Version