Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress XML Binding Development Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

7.2 Designing a Schema for Extensibility

The HydraExpress XML binding creates a perfect parser. The parser is specifically designed to efficiently process XML documents that conform to the schema provided to the compiler. The generated classes enforce the structure specified in the schema. If an XML document does not conform to the schema, the generated classes throw an exception while parsing the document.

However, this presents a problem for a schema that is intended to evolve over time. If a newer version of the schema simply adds elements, programs that use classes generated for an older version of the schema will refuse to parse the document.

One way to design a schema for extensibility is to use an optional, recurring any element. In this strategy, subsequent versions of a schema do not remove elements. At points where the schema may add elements, the schema defines an optional, recurring any element. This strategy works well with the XML bindings that HydraExpress creates.

The sample below shows a schema designed to allow future modification of the type extensibleType:

Future versions of the schema may add elements to the sequence after the element anInt, but before the any. HydraExpress creates a vector of strings to represent the any element. For clients that use this version of the schema, any elements after anInt are preserved as strings in the vector.

The class generated from this version of the schema interprets additional elements as part of the any element. Further, a client built using an extensible schema can detect when the document received uses a newer schema. If the vector contains elements, then the document contains added information.

The sample below shows an updated version of the schema:

This version adds the element aDouble to the schema. Classes generated from this version of the schema contain a member for the new element. Classes generated from the previous version of the schema interpret the new element as part of the any vector.

Notice that, although the element anInt is optional, this element cannot safely be removed from future versions of the schema. Should anInt be removed, classes generated for the updated version of the schema will fail to parse documents created by older clients when those documents contain the element anInt.



Previous fileTop of DocumentContentsIndex pageNext file

©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.