The WSIT Tutorial

@XmlElementRefs Annotation

Guideline: @XmlElementRefs maps to a xs:choice. This binds to a property with name item in the C# class. If there is another field/property named item in the Java class, there will be a name clash that .NET will resolve by generating name. To avoid the name clash, either change the name or use customization, for example @XmlElement(name="foo").

Example: Mapping a field or property using @XmlElementRefs

//-- Java code fragment
public class PurchaseOrder {
        @XmlElementRef(name="plane", type=PlaneType.class),
        @XmlElementRef(name="auto", type=AutoType.class)})
    public TransportType shipBy;

public class PlaneType extends TransportType {}

public class AutoType extends TransportType { }

public class TransportType { ... }

//-- Schema fragment
<!-- XML schema generated by wsgen -->
<xs:complexType name="purchaseOrder">
        <xs:element ref="plane"/>
        <xs:element ref="auto"/>

<!-- XML global elements -->
<xs:element name="plane" type="autoType" />
<xs:element name="auto" type="planeType" />

<xs:complexType name="autoType">
    <!-- content omitted - details not relevant to example -->

</xs:complexType name="planeType">
    <!-- content omitted - details not relevant to example -->

// .NET auto generated code from schema
public partial class purchaseOrder {
    private transportType itemField;

    [System.Xml.Serialization.XmlElementAttribute("auto", typeof(autoType), Order=4)]
    [System.Xml.Serialization.XmlElementAttribute("plane", typeof(planeType), Order=4)]
    public transportType Item
        get { return this.itemField; }
        set { this.itemField = value; }

public partial class planeType { ... } ;
public partial class autoType { ... } ;