Hi Per-Ivar, You don't need choice="true" for a collection of items - just say ordered="false" and flexible="true" on the <collection> element itself, then list the different alternatives you want to handle as child <structure>s within the collection. So something along these lines should work:
<collection type="java.util.ArrayList" field="list" ordered="false" flexible="true"> <structure name="car" type="Car" usage="optional"> <value name="name" field="name"/> </structure> <structure name="boat" type="Boat" usage="optional"> <value name="name" field="name"/> </structure> </collection> That's assuming you use different classes for cars and boats, and that you really want to require the <name> child element for each. - 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 Per-Ivar Bakke wrote: > Hi > > Does anybody know if there is a plan to support the property > combination 'choice=true' and 'flexible=true' on the structure > element? I am running version 1.1.3 now and it does not support > this. If not, is there a way around the below problem? > > I have problems figuring out how jibx could support an unordered list > with unknown elements! That is, I have the following requirements for > the XML list: > 1) Any number (zero or more) Car and Boat elements > 2) Car and Boat elements may appear in any order > 3) Any element from any other name space may appear in the list (need > to use flexible attribute for this) > 4) The solution should not require the below XML snippet to be adapted > in any way (the binding could be changed off course) > > Consider the XML snippet below: > <list> > <car> > <name>Volvo</name> > </car> > <boat> > <name>Windy</name> > </boat> > <car> > <name>Saab</name> > </car> > </list> > > Item 1 and 2 above could be parsed using the following binding: > <mapping class="TestMappings" name="list"> > <collection type="java.util.ArrayList" field="list"> > <structure choice="true" ordered="false" type="TestMapping"> > <structure name="car" field="car" usage="optional"> > <value name="name" field="name" usage="optional"/> > </structure> > <structure name="boat" field="boat" usage="optional"> > <value name="name" field="name" usage="optional"/> > </structure> > </structure> > </collection> > </mapping> > > To fulfill requirement 3 above I add the flexible attribute: > <structure choice="false" ordered="false" type="TestMapping" > flexible="true"> > I now get the below error: > Caused by: org.jibx.runtime.JiBXException: Duplicate element > "car"(line 8, col 8) > > To fix this problem I tried adding the allow-repeats attribute: > <structure choice="false" ordered="false" type="TestMapping" > allow-repeats="true" flexible="true"> > This time, jibx was only able to find the last Car (Saab) and the Boat > element in the XML snippet above! > > Any solution to this problem would be greatly appreciated! I have the > Java classes also if needed. > > > Thanks, > Per-Ivar > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jibx-users > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users