Top-level groups
XML Schemas can define a top-level group, and then use references to the group elsewhere in the schema. Here is an example:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://roguewave.com/examples/xmlbinding"
xmlns:tns="http://roguewave.com/examples/binding">
<group name="Measurement">
<choice>
<element name="Miles" type="float"/>
<element name="Kilometers" type="float"/>
</choice>
</group>
<complexType name="Distance">
<sequence>
<element name="City1" type="string"/>
<element name="City2" type="string"/>
<group ref="tns:Measurement"/>
</sequence>
</complexType>
</schema>
For the above schema, the Distance class is generated with these functions:
[get|set]City1(),
[get|set]City2(),
[get|set]Miles(), and
[get|set]Kilometers() getChoice() because of the choice construct
Here is a more complex example that has complex types under the model group:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://roguewave.com/examples/xmlbinding"
xmlns:tns="http://roguewave.com/examples/xmlbinding">
<group name="Measurement">
<sequence>
<element name="Inches">
<complexType>
<sequence><element name="val" type="string"/></sequence>.
</complexType>
</element>
</sequence>
</group>
<complexType name="Width">
<sequence>
<element name="Object">
<complexType>
<sequence><element name="val" type="string"/></sequence>.
</complexType>
</element>
<group ref="tns:Measurement"/>
</sequence>
</complexType>
<complexType name="Length">
<sequence>
<element name="Object">
<complexType>
<sequence><element name="val" type="string"/></sequence>.
</complexType>
</element>
<group ref="tns:Measurement"/>
</sequence>
</complexType>
</schema>
The generated output for the above schema would have:
A
MeasurementInches class with the functions:
[get|set]Val() A
Width class with the functions:
[get|set]WidthObject() [get|set]MeasurementInches() A
WidthObject class with the functions:
[get|set]Val() A
Length class with the functions:
[get|set]LengthObject() [get|set]MeasurementInches() A
LengthObject class with the functions:
[get|set]Val() Since there are five complex types (Length, Width, the anonymous complex type declarations for the two Object elements, and the Inches element in the Measurement model group), HydraExpress generates five classes. As described in the preceding sections, the classes MeasurementInches, LengthObject, and WidthObject represent the elements, since the complex types are anonymous declarations. The Width and Length classes represent the two named complex types.
The
MeasurementInches,
LengthObject, and
WidthObejct classes are named the way they are because they are child elements of another element, complex type, or model group. Thus the class name is formed by concatenating the parent name and the element name (see
Names and Identifiers ).
Finally, the MeasurementInches class is used from within both the Width and Length classes because both types reference the same model group.