This section describes the 'simpleType' component, which can be used to define user-defined simple datatypes. There are 3 optional child components supported 'restriction', 'list', 'union'.
If you are happy with those built-in simple datatypes offered in XSD 1.1,
you don't need to learn how define your own simple datatypes.
But if you want to be creative, you need to learn the "simpleType" component for creating new simple datatypes.
Here is an XSD template showing you how to use the "simpleType" component:
<simpleType name="type_name" final="list|union|restriction|#all">
<restriction>...</restriction>
or <union>...</union>
or <list>...</list>
</simpleType>
Some notes on using the "simpleType" component:
name="type_name" - Optional attribute to specify a name to the new datatype.
If not provided, the new datatype will be anonymous type.
final="list|union|restriction|#all" - Optional attribute to specify whether the new datatype is "final" or not.
For example,
if final="#all", the new datatype can not be used to define more datatypes in any structure;
if final="#restriction", the new datatype can not be used as the "restriction" base datatype to define more datatypes.
<restriction>...</restriction> - Optional child component to define the value space of the new datatype
as a sub set of a base datatype.
<union>...</union> - Optional child component to define the value space of the new datatype
as a union of multiple simple datatypes.
<list>...</list> - Optional child component to define the value space of the new datatype
as list values of another simple datatype.
Each "simpleType" component can only have one single child component: "restriction", "union" or "list".
Multiples are not allowed.
For example, the following XSD document uses "simpleType" components to define 2 new simple datatypes:
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book,
I get these errors:
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
simpleType_definition_test.xsd simpleType_definition_test.xml
Error:
Line number: 13
Column number: 26
Message: cvc-pattern-valid: Value '121' is not facet-valid with
respect to pattern '\d\d\d\d\d' for type 'zipType'.
Error:
Line number: 13
Column number: 26
Message: cvc-type.3.1.3: The value '121' of element 'ZipList' is
not valid.
Error:
Line number: 14
Column number: 33
Message: cvc-pattern-valid: Value 'null' is not facet-valid with
respect to pattern '\d\d\d\d\d' for type 'zipType'.
Error:
Line number: 14
Column number: 33
Message: cvc-type.3.1.3: The value '12345 null' of element
'ZipList' is not valid.
Failed with errors: 4