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="">
<!-- address.xsd
 - Copyright (c) 2002-2013 All Rights Reserved.

 <xsd:element name="address" type="addressType"/>

 <xsd:complexType name="addressType">
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city" type="xsd:string"/>


The schema represented in address.xsd is a complete schema. The XML document, address.xml, conforms to this schema:

<?xml version="1.0"?>
<!-- address.xml
 - Copyright (c) 2002-2013 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".

Table of Contents

 About This Book

 Introduction to XML Schema

 XML Editor and Schema Processor - XMLPad

 Java API for XML Processing - JAXP

 JAXP - XML Schema (XSD) Validation

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java APIs

 XML Schema Language - Basics

 Introduction of XSD Built-in Datatypes

 "string" and Its Derived Datatypes

 "decimal" and Its Derived Datatypes

 "dateTime" and Its Related Datatypes

 Miscellaneous Built-in Datatypes

 Facets, Constraining Facets and Restriction Datatypes

 "simpleType" - Defining Your Own Simple Datatypes

 Complex Element Declaration

 Identity-Constraints: unique, key and keyref

 Assertion as Custom Validation Rules

 XML Schema Location and Namespace in XML Documents

 Overriding Element Types in XML Documents

Linking Multiple Schema Documents Together

 Schema Component Reuse - "include", "redefine" or "import"

Including Old Schema Documents - "include" Component

 Including Old Schema Documents - Examples

 Including Old Schema Documents - Errors

 Redefining Old Datatypes - "redefine" Component

 Redefining Old Datatypes - XML Examples

 Redefining Old Datatypes - Errors

 Importing Declarations Across Namespaces - "import" Component

 Importing Declarations Across Namespaces - Examples

 Using Elements Declared in Different Namespaces

 Using Elements Declared in Different Namespaces - Errors


 Archived Tutorials


 Full Version in PDF/EPUB