users@jaxb.java.net

Schema binds in jaxb1, but not jaxb2

From: Kenny MacLeod <kennym_at_kizoom.com>
Date: Mon, 3 Mar 2008 12:16:11 +0000

Folks,

We currently have a JAXB1 XJC-generated binding which I'm trying to
convert to JAXB2. It's a very unpleasant (but 100% valid) schema which
required lots of binding customisations under JAXB1 to make it work.

Under JAXB2, it looks as though it just can't be bound at all. Take the
following schema fragment. Note the duplicate itdDateTime elements.

<xsd:complexType name="itdRouteType">
   <xsd:sequence>
     <xsd:sequence minOccurs="0">
       <xsd:element name="itdDateTime" type="itdDateTimeType"/>
       <xsd:element name="itdDateTime" type="itdDateTimeType"/>
     </xsd:sequence>
     <xsd:element name="itdMapItemList" type="itdMapItemListType"/>
   </xsd:sequence>
</xsd:complexType>

Under JAXB1, we have the following in the xjb file:

<jxb:bindings node="//xsd:complexType[@name='itdRouteType']">
   <jxb:bindings node=".//xsd:element[@name='itdDateTime'][1]">
     <jxb:property name="itdDateTimeDeparture"/>
   </jxb:bindings>
   <jxb:bindings node=".//xsd:element[@name='itdDateTime'][2]">
     <jxb:property name="itdDateTimeArrival"/>
   </jxb:bindings>
</jxb:bindings>

This maps the first element to "itdDateTimeDeparture" and the second to
"itdDateTimeArrival". This works great, and I think it works because
the JAXB1 runtime can handle the duplicate element names because they
are in sequence.

Under JAXB2, however, XJC rejects it entirely, since it has no way of
distinguishing one itdDateTime element from the other. It spits out the
error message "Element 'itdDateTime' shows up in more than one properties".

 From my understanding of JAXB2, this schema just cannot be XJC-bound in
its current form.

Someone please prove me wrong?

cheers
kenny