∟Including Old Schema Documents - "include" Component
This section describes why and how to include an existing schema document and reuse its datatype definitions.
When you are designing a new schema, you may want to reuse some declarations and definitions from an old schema.
This can be done easily by using the "include" component to include the old schema document into the new schema document.
To use the "include" component, you need to remember the following rules:
Rule 1. The XML representation of an "include" component is an "include" element.
Rule 2. The "include" element must have the "schemaLocation" attribute to specify where to fetch the old schema document.
Rule 3. The "include" element must appear before any element declarations or type definitions.
Below is a tutorial sample schema named address.xsd that declares an element "address" and a datatype "addressType":
The schema represented in address.xsd is a complete schema. The XML document, address.xml, conforms to this schema:
- Copyright (c) 2013, HerongYang.com, All Rights Reserved.
<street>1 Main Street</street>
As you can see, the "addressType" defined in this schema is too simple. It is only good for a small country.
In the next section, we will design a new schema to extend this definition for a bigger country.
The new schema has an "include" component to reuse the "addressType" definition described in "address.xsd".