Hi Davide,

You can't do what you want directly, but can easily fake it for 
unmarshalling with a small code change. Just define a method addItem() 
to add a new item to the collection, then use the binding structure:

<binding direction="input">
    <mapping name="root" class="Root" ordered="false" flexible="true" 
allow-repeats="true">
        <value name="tag2" field="tag2"  usage="optional"/>
        <structure name="item" type="Item"  ordered="false" 
set-method="addItem">
            <value name="title" field="title"  usage="optional" />
        </structure>
     </mapping>
</binding>

The allow-repeats="true" means JiBX will accept any number of repeats of 
the elements, and it'll call the addItem() method for each instance of 
<item> seen.

If you want to handle both marshalling and unmarshalling there's no easy 
way to do it. You could define separate bindings, one for unmarshalling 
and one for marshalling, but that can get ugly.

  - Dennis

Dennis M. Sosnoski
XML 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



mr.abanjo wrote:
> Hi,
> there is a way to have a "parent" tag with flexible= true that have a 
> collection as child?
>
> Es:
>
> <root>
>     <tag1>a</tag1>  <!-- i haven't mapped this tag -->
>     <tag2>b</tag2>
>     <item>
>        <title>c1</title>
>     </item>
>     <item>
>        <title>c2</title>
>     </item>
>     <item>
>        <title>c3</title>
>     </item>
> </foo>
>
> Mapping:
>
> <binding>
>     <mapping name="root" class="Root" ordered="false" flexible="true">
> <!-- N.B. i don't map TAG1... i use flexible=true to avoid problem to 
> unknown tags -->
>         <value name="tag2" field="tag2"  usage="optional"/>
>                <collection field="items" 
> factory="Root.itemsListFactory" usage="optional">
>                     <structure name="item" type="Item"  ordered="false">
>                           <value name="title" field="title"  
> usage="optional" />
>                     </structure>
>                 </collection>
>     </mapping>
> </binding>
>
> Flexible=true works fine, but when i have a collection as a child JIBX 
> give me an error in a compilation phase.
> It tell me that all child must have a "name". But collection doesn't 
> have it.. becouse "name" is declared in the "structure".
> How i can tell JIBX to ignore TAG1?
>
> This behaviour is very usefull, because sometime who generate the feed 
> add new tag ora attribute without advise who read them.
>
> Thanks
> Davide
>
>
>
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
> trial. Simplify your report design, integration and deployment - and focus on 
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to