4.2 Deriving Types by ExtensionDeriving Types by Extension
To create our address constructs, we start by creating a
complex type called Address in the usual way
(see address.xsd).
The Address type contains the basic elements
of an address: a name, a street and a city. (Such a
definition will not work for all countries, but it
serves the purpose of our example.) From this starting
point we derive two new complex types that contain all the
elements of the original type plus additional elements that
are specific to addresses in the US and the UK. The
technique we use here to derive new (complex) address types
by extending an existing type is the same technique we used
in in [Complex Types from Simple Types],
except that our base type here is a complex type whereas
our base type in the previous section was a simple type.
ref53
We define the two new complex types,
USAddress and UKAddress, using the
complexType
element. In addition, we indicate that the content models
of the new types are complex, i.e. contain elements, by
using the
complexContent element, and we indicate that we
are extending the base type Address by the
value of the
base attribute on the extension element.
When a complex type is derived by extension, its effective
content model is the content model of the base type plus
the content model specified in the type derivation.
Furthermore, the two content models are treated as two
children of a sequential group. In the case of
UKAddress, the content model of
UKAddress is the content model of
Address plus the declarations for a
postcode element and an exportCode
attribute. This is like defining the UKAddress
from scratch as follows:
NOTE:
Effective Content Model of UKAddress
<complexType name="UKAddress">
<sequence>
<!-- content model of Address -->
<element name="name" type="string"/>
<element name="street" type="string"/>
<element name="city" type="string"/>
<!-- appended element declaration -->
<element name="postcode" type="ipo:UKPostcode"/>
</sequence>
<!-- appended attribute declaration -->
<attribute name="exportCode" type="positiveInteger" fixed="1"/>
</complexType>
|