XML Binding Development Guide : PART II Code Generation Examples : Chapter 6 complexContent Example : An International Purchase Order Instance Document
An International Purchase Order Instance Document
We begin with a simple instance document.
 
<ipo:purchaseOrder xmlns:ipo="http://www.example.com/IPO"
orderDate="1999-12-05">
<shipTo exportCode="1" xsi:type="ipo:UKAddress"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>Helen Zoe</name>
<street>47 Eden Street</street>
<city>Cambridge</city>
<postcode>CB1 1JR</postcode>
</shipTo>
<billTo xsi:type="ipo:USAddress"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<items>
<item partNum="833-AA">
<productName>Lapis necklace</productName>
<quantity>1</quantity>
<USPrice>99.95</USPrice>
<ipo:comment>Want this for the holidays!</ipo:comment>
<shipDate>1999-12-05</shipDate>
</item>
</items>
</ipo:purchaseOrder>
The instance document contains a billTo element. As you can see from the schema in the preceding section, a billTo is an Address. The Address type has two extensions, USAddress and UKAddress, and a billTo element can be either of these types. Elements with substitutable types are required to have an xsi:type attribute that clarifies the actual type of the element.
When unmarshaling an instance document that contains substitutable elements, HydraExpress uses the xsi:type attribute to determine the correct class type to create. In your application code, you can use the class getTypeId() method to determine its type.