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

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:

  • Built-in datatypes can be used to declare an XML element or an XML attribute to be of a specific built-in datatype to help the XML document receiver to process it with better accuracy.
  • Built-in datatypes can be used to build additional new custom datatypes using <xs:simpleType> and <xs:complexType>.

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:

<data>7065616365</data>

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:

  • What values are supported by the datatype.
  • How each value can be represented in the XML document.
  • How each representation should be evaluated into a supported value.

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

  • Value Space - The value space of a datatype is the set of values that are supported by that datatype. I guess we can also call it the value set of a datatype.
  • Lexical Space - The lexical space of a datatype is the prescribed set of strings which can be mapped to values of that datatype. May be we can call it the representation set of a datatype. Each item in the set is an literal representation which can be parsed into a value in the value set.
  • Lexical Representation - A lexical representation is a single item in the Lexical Space.

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:

<A>E</A>

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

 Glossary

 References

 PDF Printing Version

Datatypes, Values and Representations - Updated in 2014, by Dr. Herong Yang