to the main page about the tutorial  THE XML REVOLUTION  -  TECHNOLOGIES FOR THE FUTURE WEB back up next

Type derivation and substitution groups

XML Schema contains a complicated type system.

Types can be derived from other types:


Subsumption:

Assume that we declare an element:

<element name="myVehicle" type="n:vehicle"/>

meaning that myVehicle elements are valid if they match the vehicle type.

Since car is derived from vehicle, myVehicle elements are also valid if they match car
- provided that we add xsi:type="n:car" to the elements (where xsi refers to http://www.w3.org/2001/XMLSchema-instance) in the instance document.


Substitution groups - an alternative to type derivation:

If we declare another element as:

<element name="myCar" type="n:car" substitutionGroup="n:vehicle"/>

then we may always use myCar elements whenever myVehicle elements are required (without using xsi:type).

This is independent of the extension/restriction inheritance hierarchy! - car is not required to be declared as a sub-type of vehicle.


Controlling derivation and subsumption:

In addition to all this,

back COPYRIGHT © 2000-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH next