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) 2013, HerongYang.com, 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.

Last update: 2013.

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 API

 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

 References

 PDF Printing Version