users@jaxb.java.net

How to customize JAXB (XJC) to imitate _at_XmlElementWrapper

From: ohad young <ohady_at_dbmotion.com>
Date: Thu, 18 Dec 2008 06:41:32 -0800 (PST)

Hi,

The default binding generates a class for each complexType. But, I’d like
to imitate @XmlElementWrapper annotation behavior for some complexTypes
which only wraps other elements. For example
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="RootElement" type="RootElementType"/>
  <xs:complexType name="RootElementType">
    <xs:sequence>
      <xs:element name="Items" type="ItemsType" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string"/>
  </xs:complexType>
  <xs:complexType name="ItemsType">
    <xs:sequence>
      <xs:element name="Item" type="ItemType" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="ItemType">
    <xs:attribute name="name" type="xs:string"/>
    <xs:attribute name="description" type="xs:string"/>
  </xs:complexType>
</xs:schema>

The default RootElement generated class will look something like:
public class RootElement {
    @XmlElement(name = "Items")
    protected ItemsType items;
    @XmlAttribute
    protected String id;

}

But, I prefer not to generate a class for ItemsType complexType but rather
have it as an @XmlElementWrapper annotation. For example:

public class RootElement {
    @XmlElementWrapper(name = "Items")
    @XmlElement(name = "Item")
    private List<Item> items;
    @XmlAttribute
    protected String id;

}

How to achieve this customization using an external binding customization
file?
Thanks, Ohad
-- 
View this message in context: http://www.nabble.com/How-to-customize-JAXB-%28XJC%29-to-imitate-%40XmlElementWrapper-tp21074055p21074055.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.