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:
All built-in datatype names must be qualified with namespace of
xmlns:xs="http://www.w3.org/2001/XMLSchema", where "xs" can be replace with any short names.
Complex built-in datatype (only 1 in XSD 1.1: "anyType") is alowed only to to be used to define new complex datatypes.
"anyType" (the only complex built-in datatype in XSD 1.1) is alowed to be used as the base datatype
for "restriction" construction components.
"anyType" is not alowed to be used as the base datatype for "extension" construction components,
since "anyType" is the largest/biggest complex datatype.
Simple built-in datatypes (49 of them in XSD 1.1) are alowed to be used to define new simple and complex datatypes.
Simple built-in datatypes are allowed to be used as the base type for "restriction" construction components,
member datatypes for "union" construction structions, or the item datatype for "list" construction components
to define new simple datatypes.
Simple built-in datatypes are allowed to be used as the base type for "extension" construction components
to define new complex datatypes.
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) 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>