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 defined 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) 2002-2013 HerongYang.com. 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:

herong> 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.

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

 Glossary

 Archived Tutorials

 References

 Full Version in PDF/EPUB