This isn't exactly what you had in mind but I think it will accomplish your goal.

Define a class Bar which Foo will have one instance of. Then define Bar to have fields left and right. Your mapping would then look something like:

<class name="Foo">
   <map-to xml="foo"/>
   <class name="Bar">
        <map-to xml="bar />
        <field name "left" type="integer">
            <bind-xml name="left" node="element"/>
       </field>
       <field name "right" type="integer">
            <bind-xml name="right" node="element"/>
       </field>
   </class>
</class>

I've never used the location attribute before so I can't really comment on how it should/does work but I have used a structure similar to the above successfully.

Ben

Dan Marcus wrote:

Hi-
I've just started using Castor and am excited about its potential, but I've run into a problem. I would like to map two fields to a single wrapper element. I tried using the 'location' attribute of bind-xml, but it yielded two wrapper elements. The example below, I hope, will make this clearer. Is it possible to nest multiple elements within a single wrapper element? Thanks,
Dan Marcus
Given a bean like this:
public class Foo {
private int barLeft;
private int barRight;
public int getBarLeft(){
return barLeft;
}
public int getBarRight(){
return barRight;
}
}
I would like to create xml like this: <foo>
<bar>
<left/> <!-- Note left and right are both within a single bar-->
<right/> </bar>
</foo>
Unfortunately, using the mapping below, it looks like this:
<foo>
<!-- Note the 2 bar elements! -->
<bar>
<left>0</left>
<bar>
<bar>
<right>5</right>
<bar>
</foo>
Here's the mapping:
<class name="Foo">
<map-to xml="foo"/>
<field name "barLeft" type="integer">
<bind-xml name="left" location="bar" node="element"/>
</field>
<field name "barLeft" type="integer">
<bind-xml name="right" location="bar" node="element"/>
</field>
</class>

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev




Reply via email to