users@jaxb.java.net

Re: How do I separate the <xsd:choice/> sub elements into individual list properties?

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 12 Aug 2011 15:31:53 +0200

There is no way for two separate lists to maintain the ordering of elements
in the XML document. The XML Schema says: here comes a mixture of this and
that, and that's what JAXB is bound to deliver.

You can easily write a generic method for extracting a List<This> or a
List<That> from a List<JAXBElement>.

-W


On 12 August 2011 15:02, Jarrod Roberson <jarrod_at_vertigrated.com> wrote:

> I posed this question on stackoverflow.com, I am posting a link to it for
> those of you that use it.
>
>
> http://stackoverflow.com/questions/7033600/how-do-i-separate-the-xsdchoice-sub-elements-into-individual-collection-prope
>
> <xsd:element name="navmap">
>
> <xsd:complexType>
>
> <xsd:choice minOccurs="0" maxOccurs="unbounded">
>
> <xsd:element ref="navitem"/>
>
> <xsd:element ref="debug"/>
>
> </xsd:choice>
>
> <xsd:attribute name="focus" type="xsd:string" use="optional"/>
>
> </xsd:complexType>
> </xsd:element>
>
> by default generates this
>
> @XmlElements({
>
> @XmlElement(name = "navitem", type = Navitem.class),
>
> @XmlElement(name = "debug", type = Debug.class)
>
> })
>
> protected List<Object> navitemOrDebug;
>
>
> and I want something like this
>
> @XmlElements({
>
> @XmlElement(name = "navitem", type = Navitem.class)
>
> })
>
> protected List<Navitem> navitems;
>
> @XmlElements({
>
> @XmlElement(name = "debug", type = Debug.class)
>
> })
>
> protected List<Debug> debugs;
>
> How do I get the desired output?
>