Hi Steven,

I don't see anything obviously wrong with what you're doing. Here's a 
sample from the JiBX build test cases:

  <mapping name="myelement" class="simple.MyClass3">
    <structure ordered="false" choice="true">
      <value name="a" field="a" usage="optional"/>
      <value name="b" field="b" usage="optional"/>
      <value name="c" field="c" usage="optional"/>
      <value name="d" field="d" usage="optional"/>
    </structure>
    <value name="e" field="e" usage="optional" format="char.string"/>

Here's a corresponding XML:

<myelement>
  <b>The Answer</b>
  <dimension width="4" height="6"/>
  ...

It may be that there's some strange error coming in from the nesting 
inside an abstract mapping, since that's the only thing that seems to be 
different. Can you create a Jira and attach a test project to 
demonstrate the problem?

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Steven E. Harris wrote:
> I'm struggling trying to figure out the right way to write a binding
> for an xsd:choice structure. Consider the following schema fragment:
>
>    <xs:simpleType name="Tmac-48">
>       <xs:restriction base="xs:string">
>          <xs:pattern value="[\p{Nd}A-F]{2}(-[\p{Nd}A-F]{2}){5}"/>
>       </xs:restriction>
>    </xs:simpleType>
>
>    <xs:simpleType name="Teui-48">
>       <xs:restriction base="Tmac-48"/>
>    </xs:simpleType>
>
>    <xs:simpleType name="Teui-64">
>       <xs:restriction base="xs:string">
>          <xs:pattern value="[\p{Nd}A-F]{2}(-[\p{Nd}A-F]{2}){7}"/>
>       </xs:restriction>
>    </xs:simpleType>
>
>    <xs:simpleType name="Tfoo">
>       <xs:restriction base="xs:normalizedString"/>
>    </xs:simpleType>
>
>    <xs:group name="Gdevice-id">
>       <xs:choice>
>          <xs:element name="mac-48" type="Tmac-48"/>
>          <xs:element name="eui-48" type="Teui-48"/>
>          <xs:element name="eui-64" type="Teui-64"/>
>       </xs:choice>
>    </xs:group>
>
>    <xs:complexType name="Tmachine">
>       <xs:sequence>
>          <xs:group ref="Gdevice-id"/>
>          <xs:element name="foo" type="Tfoo"/>
>       </xs:sequence>
>    </xs:complexType>
>
>
> That is, there's a complex type "Tmachine" which consists of one of a
> "mac-48", "eui-48", or "eui-64" element, and one "foo" element, like
> so, materialized in an element called "machine":
>
>    <machine>
>       <mac-48>11-22-33-44-55-66</mac-48>
>       <foo>bar</foo>
>    </machine>
>
> Alternately, one should be able to write:
>
>    <machine>
>       <!-- Note the different kind of device id: -->
>       <eui-48>11-22-33-44-55-66</eui-48>
>       <foo>bar</foo>
>    </machine>
>
> My JiBX binding for this "Tmachine" type looks like this:
>
>    <mapping class="Machine" abstract="true">
>       <structure choice="true" ordered="false">
>          <value name="mac-48" field="mac48"/>
>          <value name="eui-48" field="eui48"/>
>          <value name="eui-64" field="eui64"/>
>       </structure>
>       <value name="foo" field="foo"/>
>    </mapping>
>
> It's referenced elsewhere in the binding like this:
>
>   <structure name="machine" field="machine"/>
>
> where the field "machine" is of type "Machine" in the containing
> class.
>
> When I attempt to unmarshall the element <machine> above, JiBX throws
> an exception reporting:
>
>   org.jibx.runtime.JiBXException:
>     Missing required element "{...}eui-48"(line 4, col 45)
>
> That is, it sees the "mac-48" element and accepts that, but then
> demands an "eui-48" element to follow immediately, which seems as
> though it's mistakenly treating the xsd:choice as a sequence.
>
> Actually, if I put a "eui-48" element first followed by a "mac-48"
> element, JiBX still demands a "mac-48" element. If I put a "mac-48"
> element first followed by an "eui-48" element, JiBX still demands an
> "eui-48" element. There's no way to satisfy it, even by violating my
> own schema.
>
> When I run the JiBX compiler, I see the following output (namespaces
> elided):
>
>        component property machine (Machine)
>         object binding for Machine create class Machine
>          structure ordered
>           mapping reference to Machine using property "this" (Machine)
>            base mapping wrapper
>             object binding for Machine ("this" reference) create class Machine
>              structure ordered
>               structure choice
>                element {...}:mac-48 from property mac48 (java.lang.String)
>                element {...}:eui-48 from property eui48 (java.lang.String)
>                element {...}:eui-64 from property eui64 (java.lang.String)
>               element {...}:foo from property foo (java.lang.String)
>
> The output shows acknowledgment of the choice structure.
>
> Is there an obvious error in my binding that's causing JiBX to require
> all the would-be choice alternates?
>
>   

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to