This section describes a tutorial example on how to derive simple datatypes by restricting built-in datatypes with simpleType components.
Every built-in datatype has its own default data value range.
If you want to restrict the default data value range, you can use restriction facets
supported by the built-in datatype.
To apply restriction facets to a built-in datatype,
you need to use a Simple Type Definition Component to define a derived datatype
based on XML representation rules.
Rule 1. The XML representation of a Simple Type Definition Component is a "simpleType"
element.
Rule 2. A "restriction" sub element must be used to specify any restriction facet.
Rule 3. The built-in datatype must be specified as the "base" attribute of the "restriction" element.
Rule 4. One or more restriction facets can be included in the "restriction" element
as sub elements.
Here is a schema template that defines a derived datatype from a built-in datatype:
where "element_name" is the name of the XML element, "base_type_name" is
a built-in datatype serving as the base datatype, and "my_type_name"
is the new datatype derived from the built-in datatype with some restriction facets applied.
Here is a list of restriction facets that are supported by most built-in datatypes:
minInclusive - Inclusive minimum value.
minExclusive - Exclusive minimum value.
maxInclusive - Inclusive maximum value.
maxExclusive - Exclusive maximum value.
enumeration - One valid value. Repeat this statement to provide multiple values.
whiteSpace - How to handle white spaces: "preserve|replace|collapse".
pattern - A regular expression the value must match.
length - Number of characters.
minLength - Minimum number of characters.
maxLength - Maximum number of characters.
totalDigits - Maximum number of digits.
fractionDigits - Maximum number of digits in the fraction part.
The syntax of a facet element is:
<xsd:facet_name value="facet_value">
Besides restricting base datatypes to derive new datatypes, we can also derive
new datatypes by define "union" or "list" of base datatypes.
Union: A collection of base datatypes. A value is valid for a union datatype
if and only it is valid for one of the base datatypes.