To use external parsed entities, we will create an XML document with
the pattern we want to include:
<?xml version="1.0"?>
<xs:pattern value=".+(Z|[+-].{5})"
xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
Note that including a namespace declaration in this file (which will
be used as an external parsed entity) is not strictly mandatory, if
we are sure that this entity will always be used in documents in
which the namespace has already been defined with the same prefix.
However, even in this case, the redefinition of the namespace is
allowed though it will have no effect. Defining it will guarantee
that if another prefix has been used in the included document, the
snippet that we include will still be understood as belonging to the
W3C XML Schema namespace. To use this entity, it must be declared in
the internal or external DTD of our schema and referred to in our
derivations:
<?xml version="1.0"?>
<!DOCTYPE xs:schema[
<!ENTITY TZ-pattern SYSTEM "pattern.ent">
]>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="myDate">
<xs:restriction base="xs:date">
&TZ-pattern;
</xs:restriction>
</xs:simpleType>
<xs:element name="myDate" type="myDate"/>
</xs:schema>
The interesting thing here is we have a finer granularity than we
could have achieved using the W3C XML Schema inclusion mechanisms,
which manipulate only global components. The price for using a
general purpose inclusion mechanism such as external parsed entities
(or XInclude, discussed in the next section) is that this mechanism
doesn't implement any of the semantics of W3C XML
Schema and doesn't allow any redefinition. Beyond
this simple example, other DTD features, such as internal parsed
entities, and even parameter entities can be used in conjunction with
W3C XML Schema to produce innovative combinations!