Hi Dennis Thank you for the suggestion, I will try it out today - looking at it makes perfect sense.
Thanks Jorge DSosnoski wrote: > > Hi Jorge, > > That exception text is wrong in this case. From looking at the actual > code generation, you'd get this error when the items in an ordered > collection (like yours) are out of order. > > From looking at your first email, you appear to have a repeating > sequence rather than just repeating elements. If you try to put this > repeating sequence into a simple <collection> it's not going to work, > because you're telling JiBX to expect a collection where the individual > elements may repeat, but the <e1>s will all occur before any <e2>, etc. > > You've got several ways of handling this in JiBX. One would be to just > make the collection unordered (with an ordered="false" attribute). That > would be sufficient to let you marshal and unmarshal valid documents, > but would mean that you could create invalid documents, if you (for > instance) added two Type1 values to the collection right after each other. > > You could also handle this with nested collections, which would allow > you to use JiBX to enforce the schema ordering. But using an inner > collection to represent the items in the sequence is both overkill and > confusing from the user standpoint. Why not instead just create a class > to represent an instance of the sequence: > > class TypeSequence { > private Type1 type1; > private Type2 type2; > private Type3 type3; > ... > } > > Then you just use a simple <structure> inside a <collection> in the > binding: > > <collection field="children" factory="SomeElement.listFactory" > usage="optional"> > <structure type="TypeSequence> > <structure field="type1"/> > <structure field="type2"/> > <structure field="type3" usage="optional"/> > </structure> > </collection> > > Doing it this way gives you a data structure that matches the schema > rules, so it's easier to work with. > > Going a little further, if you really only have a single text value for > each of these items, you could eliminate the Type1...n classes > completely and just use String fields within the TypeSequence. > > Hope this gives you some ideas for going forward, > > - 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 > > > > Quecas wrote: >> Ok, I've managed to jibx comiple my mapping definition. Marshaling is >> also >> working, but only for 1 iteration of the collection. As soon as I iterate >> more than once, an exception is thrown; "org.jibx.runtime.JiBXException: >> Collection item of type Type1 has no binding defined". >> >> my binding now looks somthing like: >> >> </binding> >> <mapping name="e1" class="Type1"> >> <value field="value" style="text" usage="required"/> >> </mapping> >> <mapping name="e2" class="Type2"> >> <value field="value" style="text" usage="required"/> >> </mapping> >> <mapping name="e3" class="Type3"> >> <value field="value" style="text" usage="optional"/> >> </mapping> >> >> <structure name="someElement" field="someElement" usage="optional" >> type="SomeElement"> >> <collection field="children" factory="SomeElement.listFactory" >> usage="optional"> >> <structure type="Type1" usage="required"/> >> <structure type="Type2" usage="required"/> >> <structure type="Type3" usage="optional"/> >> </collection> >> </structure> >> </binding> >> >> P.S. One thing is confusing with this error, especially with more than >> two >> iterations; it seems that the exception is only thrown on the first >> element >> of the last iteration. >> >> Has anyone out there had the same problem? >> >> Thanks >> Jorge >> >> >> >> >> >> Quecas wrote: >> >>> Hi all, >>> >>> I have just started using jibx since I would like to (possibly) change >>> from >>> jaxb. >>> >>> I am having difficulty defining a mapping to correspond to a customers >>> schema, especially a collection to a sequence that houses repeating >>> elements, e.g. >>> <root> >>> <someElement> >>> <e1>aaa</e1> (required) >>> <e2>bbb</e2> (required) >>> <e3>ccc</e3> (optional) >>> <e1>ddd</e1> (required) >>> <e2>eee</e2> (required) >>> <e1>fff</e1> (required) >>> <e2>ggg</e2> (required) >>> <e3>hhh</e3> (optional) >>> </someElement> >>> </root> >>> >>> I have spent hours trying to get a mapping definitions that works, but >>> to >>> no >>> avail - could someone please point me in the right direction. >>> >>> Thanks >>> >>> ------------------------------------------------------------------------- >>> This SF.Net email is sponsored by the Moblin Your Move Developer's >>> challenge >>> Build the coolest Linux based applications with Moblin SDK & win great >>> prizes >>> Grand prize is a trip for two to an Open Source event anywhere in the >>> world >>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>> _______________________________________________ >>> jibx-users mailing list >>> jibx-users@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/jibx-users >>> >>> >>> >> >> > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the > world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jibx-users > > -- View this message in context: http://www.nabble.com/Collection-difficulty-tp19666104p19684926.html Sent from the jibx-users mailing list archive at Nabble.com. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users