Defining New Datatypes with Built-in Datatypes

This section describes how to define or contruct new datatypes using built-in datatypes with a simple XSD document example.

When built-in datatypes are used to define (or construct) new datatypes, we need to remember these rules:

Here is a simple XSD document example on how to construct or define new datatypes using built-in datatypes:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- datatype_definition.xsd
 - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved.
-->

 <!-- Using simple built-in datatype to define new simpleType -->
 <xs:simpleType name="zipType">
  <xs:restriction base="xs:string">
   <xs:maxLength value="5"/>
  </xs:restriction>
 </xs:simpleType>

 <!-- Using complex built-in datatype to construct new complexType -->
 <xs:complexType name="tableType">
  <xs:complexContent>
   <xs:restriction base="xs:anyType">
    <xs:sequence>
    <xs:element name="tr" type="xs:anyType" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="border" type="xs:string"/>
   </xs:restriction>
  </xs:complexContent>
 </xs:complexType>

<!-- Using simple built-in datatype to construct new complexType -->
 <xs:complexType name="length">
  <xs:simpleContent>
   <xs:extension base="xs:integer">
    <xs:attribute name="unit" type="xs:string"/>
   </xs:extension>
  </xs:simpleContent>
 </xs:complexType>

</xs:schema>

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 APIs

 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

 Archived Tutorials

 References

 Full Version in PDF/EPUB