The WSIT Tutorial

List of Optional Elements

Guideline: This is the same as above except that a collection type such as List<Integer> maps to a repeating unbounded occurrence of an optional (minOccurs="0") but not nillable element. This in turn binds to .NET type int[]. This is more developer friendly. However, when marshalling, JAXB will marshal a null value within the List<Integer> as a value that is absent from the XML instance.

Example: Collection to a list of optional elements

//-- Java code fragment
public PurchaseOrder {
    public List<Integer> items;

//-- Schema fragment
<xs:element name="po" type="purchaseOrder">
<xs:complexType name="purchaseOrder">
        <xs:element name="items" type="xs:int"
                    minOccurs="0" maxOccurs="unbounded"/>

// .NET auto generated code from schema
partial class purchaseOrder {
    private int[] itemsField;

    public int[] items
        get { return this.itemsField; }
        set { this.itemsField = value; }