Like most major coding languages, XML Schema allows you to create data types that
inherit some of their elements from other data types. This is called defining a type by
extension. For example, you could create a new type called alienInfo
,
that extends the personalInfo
structure defined in Example 2.4 by adding a new element called planet
.
Types defined by extension have four parts:
The name of the type is defined by the
name
attribute of thecomplexType
element.The
complexContent
element specifies that the new type will have more than one element.Note If you are only adding new attributes to the complex type, you can use a
simpleContent
element.The type from which the new type is derived, called the base type, is specified in the
base
attribute of theextension
element.The new type’s elements and attributes are defined in the
extension
element, the same as they are for a regular complex type.
For example, alienInfo
is defined as shown in Example 2.13.
Example 2.13. Type defined by extension
<complexType name="alienInfo"> <complexContent> <extension base="personalInfo"> <sequence> <element name="planet" type="xsd:string"/> </sequence> </extension> </complexContent> </complexType>