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

Redefining Old Datatypes - "redefine" Component

This section describes a tutorial example on how to redefine datatypes defined in other schema documents.

Some you may want to revise some datatype definitions in an existing schema and make a newer version. The new version of the schema document can use the "redefine" component to include the old schema document and redefine one or more datatypes defined in the old schema document. To use the "redefine" component, you need to remember the following rules:

Rule 1. The XML representation of an "redefine" component is an "redefine" element.

Rule 2. The "redefine" element must have the "schemaLocation" attribute to specify where to fetch the old schema document.

Rule 3. The "redefine" element must have one or more datatype definition components that redefine datatypes from the old schema document.

Rule 4. A redefined datatypes must have same name as the base datatype.

Rule 3. The "redefine" element must appear before any element declarations or type definitions.

Below is a tutorial sample schema named address_us_redefine.xsd that redefines the datatype "addressUsType" using the "redefine" component:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:annotation>
  <xsd:documentation>address_us_redefine.xsd
   Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
  </xsd:documentation>
 </xsd:annotation>
 
 <xsd:redefine schemaLocation="address_us.xsd">
  <xsd:annotation>
   <xsd:documentation>
    Modifying the "addressUsType" definition 
   </xsd:documentation>
  </xsd:annotation>
  
  <xsd:complexType name="addressUsType">
   <xsd:complexContent>
    <xsd:extension base="addressUsType">
     <xsd:sequence>
      <xsd:element name="country" type="xsd:string"/>
     </xsd:sequence>
    </xsd:extension>
   </xsd:complexContent>
  </xsd:complexType>
 </xsd:redefine>

</xsd:schema>

As you can see, in this new version of the US address schema, we redefined the "addressUsType" datatype. We did not add any new element declaration. The "addressUs" element declaration in the old schema document is still valid. But it will take the new definition of "addressUsType. See the next section for examples of XML documents that conform to this new schema.

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
Redefining Old Datatypes - "redefine" Component