Skip Headers

# sequence or choice Structure Containing a group

Previous

Next

You can use the `jaxb:class` customization with a `sequence` or `choice` structure that contains a `group`. Example: jaxb:class Customization of a sequence Structure Containing a group shows a `jaxb:class` customization of a `sequence` structure containing a `group` structure.

jaxb:class Customization of a sequence Structure Containing a group

    <xsd:element name="employee">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:class name="EmploymentInfo"/>
                    </xsd:appinfo>
                </xsd:annotation>
                <xsd:element name="id" type="xsd:int"/>
                <xsd:group ref="G1"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:group name="G1">
        <xsd:annotation>
            <xsd:appinfo>
                <jaxb:class name="Period"/>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="startDate" type="xsd:date"/>
            <xsd:element name="endDate" type="xsd:date"/>
        </xsd:sequence>
    </xsd:group>

This directs the JAXB compiler to create an inner class named `EmploymentInfo` in the owning element's class for the `sequence` structure and an external wrapper class named `Period` for the `group` structure. The inner class references the external wrapper class. Use an `EISCompositeObjectMapping` (with XML records) or an `XMLCompositeObjectMapping` to map a Java attribute to this inner class.

For more information, see "XML Composite Object Mapping". The same applies to an `EISCompositeObjectMapping` with XML records (see "EIS Composite Object Mapping".