This section describes what are built-in datatypes and how to use them to declare elements and attributes.
What are built-in datatypes? Built-in datatypes are datatypes defined in XML Schema specification.
Since they already defined, built-in datatypes are ready to be used in a schema to declare elements or attributes.
There are 58 built-in datatypes defined in XML Schema 1.0. They are related to each other as shown in the diagram below:
Rule 1. Build-in datatype names have the namespace name of "http://www.w3.org/2001/XMLSchema".
Rule 2. The special built-in datatype "anyType" is a complex datatype. It can only be used to declare an element.
Rule 3. The special built-in datatype "anySimpleType" is a simple datatype.
It can be used to declare an element or an attribute.
Rule 4. All other built-in datatypes are simple datatypes. They can be used to declare elements or attributes.
Here is a sample schema that uses built-in datatypes to declare one element and three attributes:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- builtin_datatypes.xsd
- Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
-->
<!-- Using built-in datatype to declare an element -->
<xs:element name="message" type="xs:string"/>
<xs:element name="profile">
<xs:complexType>
<!-- Using built-in datatypes to declare attributes -->
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="age" type="xs:nonNegativeInteger"/>
<xs:attribute name="birthDate" type="xs:date"/>
</xs:complexType>
</xs:element>
</xs:schema>