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

2.3 XML Schema

There are several ways to define a schema for an XML document. HydraExpress supports the W3C XML Schema definition language. XML Schema documents are themselves XML. XML Schema offers the ability to express complex document structures. The language includes a large set of primitive datatypes and allows schema designers to create new datatypes based on the primitive datatypes. The XML Schema specifications are available online at the W3C web site.

Classes in a HydraExpress XML binding closely follow the definitions in the schema. For example, given the XML Schema document below:

The default configuration of the HydraExpress code generator creates a C++ XML binding with the structure shown in Figure 2:

Figure 2: C++ classes for the greeting schema

HydraExpress creates classes that closely correspond to the definitions in the schema. The schema defines a type GreetingType that contains a single element of type xsd:string. HydraExpress creates a class GreetingType that contains a single std::string. The schema defines a top level element named Greeting of type GreetingType. HydraExpress creates a class Greeting that derives from class GreetingType.

Class GreetingType represents the XML Schema type GreetingType. The class provides access to the message element by means of a getMessage accessor and a setMessage mutator. The class provides a pair of marshal methods that produce XML, and a pair of unmarshal methods that populate an instance of the class from XML. Since class GreetingType represents a datatype rather than a specific element, the default name of a GreetingType object is "GreetingType" in the default namespace.

Class Greeting represents the greeting element of the schema. Since the greeting element is of type GreetingType, class Greeting inherits from class GreetingType. The default name of a Greeting object is "greeting". Greeting overrides the marshal methods and one of the unmarshal methods so that these methods use the name of the element, "greeting", rather than the name of the type, "GreetingType".

Creating an XML document from the generated classes is simple. The code sample below is a complete program that creates an XML document that follows the schema above:

The program produces the output shown below:

Reading an XML document with HydraExpress is equally simple. The code sample below unmarshals an XML document into a Greeting object, modifies the contents of the object, and then writes the object to the standard output:

The program produces the output shown below:



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.