Thanks, Ben, for your suggestion. However, I am trying to map existing classes (actually they're classes generated by torque that are part of a working application), so I don't have the luxury of defining a different class structure.
Perhaps this is an ill-posed problem, since the existing classes are substantially flatter than the desired xml structure. Does anybody know if there's a 'pull' type framework for marshalling java objects to xml? -----Original Message----- From: Ben Redman [mailto:[EMAIL PROTECTED] Sent: Friday, June 06, 2003 3:20 AM To: [EMAIL PROTECTED] Subject: Re: [castor-dev] need help wrapping elements 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 ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
