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

Using Elements Declared in Different Namespaces

This section describes a tutorial example on how to use imported element declarations from a different namespace.

In the previous section, we wrote a new schema called xhtml_import.xsd that imported elements decarations from another namespace: xmlns:xhtml="http://www.w3.org/1999/xhtml". The final schema document represented a single schema with declarations from multiple namespaces:

  • The root "book" element is declared with no namespace.
  • Child elements "title" and "author" are declared with no namespace.
  • Child elements "p" "pre", and "ul" are declared in the namespace of http://www.w3.org/1999/xhtml.

When writing XML documents to conform to a schema with multiple namespaces, you need to remember the following rules:

  • A namespace prefix must be declared for each namespace involved in XML document.
  • The correct namespace prefix must be used for each element that is defined in a named namespace.

Here is a good example XML document, xhtml_import.xml, that conforms to xhtml_import.xsd:

<?xml version="1.0"?>
<book xmlns:xhtml="http://www.w3.org/1999/xhtml">
<!-- xhtml_import.xml
 - Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
-->

 <title>XML Schema Tutorials</title>
 <author>Herong Yang</author>
 
 <xhtml:p>What is XML Schema? ...</xhtml:p>
 <xhtml:pre>... schema code ...</xhtml:pre>

</book>

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
Using Elements Declared in Different Namespaces