The WSIT Tutorial

Default Binding

The following is the default binding of an optional (minOccurs="0") and nillable(nillable="true") element:

//-- XML schema fragment
<xs:element name="person" type="Person"
<xs:complexType name="Person">
    <xs:sequence>
        <xs:element name="name" type="xs:string" 
                    nillable="true" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
...

// Binding
public class Person {
    JAXBElement<String> getName() {...};
    public void setName(JAXBElement<String> value) {...}
}

Since the XML element name is both optional and nillable, it can be represented in an XML instance in one of following ways:

<!-- Absence of element name-->
<person>
    <-- element name is absent -->
</person>

<!-- Presence of an element name -->
<person>
    <name xsi:nil="true"/>
</person>

The JAXBElement<String> type roundtrips the XML representation of name element across an unmarshal/marshal operation.