XSD Tutorials - Herong's Tutorial Examples - Version 5.10, by Dr. Herong Yang
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":
<?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- address.xsd - Copyright (c) 2013, HerongYang.com, All Rights Reserved. --> <xsd:element name="address" type="addressType"/> <xsd:complexType name="addressType"> <xsd:sequence> <xsd:element name="street" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
The schema represented in address.xsd is a complete schema. The XML document, address.xml, conforms to this schema:
<?xml version="1.0"?> <address> <!-- address.xml - Copyright (c) 2013, HerongYang.com, All Rights Reserved. --> <street>1 Main Street</street> <city>Vatican</city> </address>
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".
Last update: 2013.
Table of Contents