XML Binding Development Guide : PART II Code Generation Examples : Chapter 4 Purchase Order Example & Namespace Qualification
Chapter 4 Purchase Order Example & Namespace Qualification
Purpose and Overview
This example illustrates the more advanced concepts of namespace qualification and collection support in HydraExpress. This example expands on the basic Purchase Order example and illustrates how namespace qualification affects usage of the generated classes. The example also illustrates how to use the collection support provided by HydraExpress for schemas that have element declarations with the maxOccurs attribute set to a value greater than one, or set to unbounded.
NOTE >> The example program in this chapter uses SourcePro C++ classes.
The XML Schema
The XML Schema below describes the purchase order. Like the basic Purchase Order example, this example is taken from the XML Schema Part 0: Primer document, section 3. The structure of this schema is identical to the structure for that of the basic example; note, however, that the targetNamespace attribute is defined on the schema element and that the elementFormDefault attribute is set to qualified. This means that all elements in an instance document of this schema are namespace-qualified.
 
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:po="http://www.example.com/PO1"
targetNamespace="http://www.example.com/PO1"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
 
<annotation>
<documentation xml:lang="en">
Purchase order schema for Example.com.
Copyright 2000 Example.com. All rights reserved.
</documentation>
</annotation>
 
<element name="purchaseOrder" type="po:PurchaseOrderType"/>
<element name="comment" type="string"/>
 
<complexType name="PurchaseOrderType">
<sequence>
<element name="shipTo" type="po:USAddress"/>
<element name="billTo" type="po:USAddress"/>
<element ref="po:comment" minOccurs="0"/>
<element name="items" type="po:Items"/>
</sequence>
<attribute name="orderDate" type="date"/>
</complexType>
...
</schema>
The XML Document
The XML below shows a portion of the example purchase order taken from section 3 in XML Schema Part 0: Primer. This XML document conforms to the namespace qualification rules defined in the previous schema. Note that all elements in the document are in the namespace "http://www.example.com/PO1". The top-level element apo:purchaseOrder declares that the prefix apo corresponds to the namespace "http://www.example.com/PO1". Each element in the document has the prefix apo, therefore each element is within the namespace "http://www.example.com/PO1".
 
<?xml version="1.0"?>
<apo:purchaseOrder xmlns:apo="http://www.example.com/PO1"
orderDate="1999-10-20">
<apo:shipTo country="US">
<apo:name>Alice Smith</apo:name>
<apo:street>123 Maple Street</apo:street>
<apo:city>Mill Valley</apo:city>
<apo:state>CA</apo:state>
<apo:zip>90952</apo:zip>
</apo:shipTo>
...
</apo:purchaseOrder>