XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
Using XML Schema Built-in Datatypes
This section describes what is a built-in datatype and how to use a built-in datatype.
XML Schema 1.0 specification provides about 46 built-in datatypes. Here are some examples of built-in datatypes:
Rule 1. All built-in datatypes are simple datatypes, which do not allow any attributes or sub (child) elements if it is used in an element declaration component.
Rule 2. Build-in datatype names have the namespace name of "http://www.w3.org/2001/XMLSchema".
Here is a sample schema, holiday.xsd, that uses the built-in datatype "date":
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- holiday.xsd - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <!-- Using XML Schema built-in datatype "date" --> <xs:element name="holiday" type="xs:date"/> </xs:schema>
The following XML document, holiday.xml, conforms to holiday.xsd:
<?xml version="1.0"?> <holiday>2007-01-01</holiday>
The following XML document, holiday_error.xml, does not conform to holiday.xsd, because the content of "holiday" element is not a "date" value:
<?xml version="1.0"?> <holiday>New Year Day</holiday>
Table of Contents
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
Schema and Schema XML Representation
Checking Schema Documents - XsdSchemaChecker.java
Creating Schema Documents - "schema" Element
Declaring Root Elements - "element" Element
Specifying Element Datatype - "type" Attribute
►Using XML Schema Built-in Datatypes
Using XML Schema Built-in Datatypes Incorrectly
Validating XML Documents against Schema Documents
Deriving New Simple Datatypes - "simpleType" Element
Defining Complex Datatypes - "complexType" Element
Validation Error Examples on Complex Datatypes
Introduction of XSD Built-in Datatypes
"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
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