This section describes a tutorial example on how to define complex base datatype and derived datatypes.
Sometimes when you declaring an element in a schema, you want to declare it with a default datatype
and offer some optional derived datatypes. The conforming XML documents can then use the special attribute
"type="derived-datatype"" to override the base datatype with an optional derived datatype.
For example, a "contact" element may be declared using a base datatype "contactType"
that captures only a "name" child element.
But you may want to create two derived datatypes:
"phoneContactType" - A "contactType" with an extra child element "phone".
"emailContactType" - A "contactType" with an extra child element "email".
With the base datatype and two derived datatypes, a "contact" element can be constructed
in three ways now:
Staying with the base datatype "contactType" - "name" only.
Overriding the base datatype with "phoneContactType" - "name" and "phone"
Overriding the base datatype with "emailContactType" - "name" and "email"
Rule 1. A derived datatype must be defined with a "restriction" or "extension" component
on the base datatype.
Here is a good sample schema, directory.xsd, that defines a base datatype and two derived datatypes:
Notice that an extra datatype "webContactType" is defined in the schema to test an error condition
described in the next section. Tutorials and example XML documents on how to override base datatypes
with derived datatypes are given in the next section.