XML Schema Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.10

Including Old Schema Documents - Errors

This section describes a tutorial example of element declaration and datatype definition colliding with those in the included schema.

When an "include" component is used, the specified schema document is actually merged into the current schema document to represent a single schema.

As a single schema, you need to watch out some schema general rules like:

Rule 1. A global element can not be declared more than once.

Rule 2. A global datatype can not be definde more than once.

For example, the schema, address_include_error.xsd, listed below has two errors. It is trying to re-define "addressType" and re-declare "address".

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:annotation>
  <xsd:documentation>address_include_error.xsd
   Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
  </xsd:documentation>
 </xsd:annotation>

 <xsd:include schemaLocation="address.xsd">
 </xsd:include> 
 
 <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:element name="state" type="xsd:string"/>
   <xsd:element name="zip" type="xsd:string"/>
  </xsd:sequence>
 </xsd:complexType>

</xsd:schema>

Here are the errors reported by the schema checker program, XsdSchemaChecker.java:

>java XsdSchemaChecker address_include_error.xsd

Error:
   Line number: 7
   Column number: 50
   Message: sch-props-correct.2: A schema cannot contain two global
   components with the same name; this schema contains two 
   occurrences of ',address'.

Error:
   Line number: 9
   Column number: 38
   Message: sch-props-correct.2: A schema cannot contain two global
   components with the same name; this schema contains two 
   occurrences of ',addressType'.

Failed with 2 errors.

Sections in This Chapter

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

Dr. Herong Yang, updated in 2007
Including Old Schema Documents - Errors