Skip to main content

Jaxb marshalling more than one object

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2010-04-28

Hi, I'm wondering how do I go about marshalling more than one object to XML? and conversely how best to unmarshal the resultant XML document? I'm quite dispondant at the moment, despite continuous effort I'm not getting anywhere.
I know I'm getting it wrong, I can do this with 1 object no problem, but how can I do it with more than one? Could I use a List? Array? I need all objects to be in one XML file so that rules out just using lots of XML files of course.
I would genuinely appreciate seeing a working example of the classic jaxb marshalling code with the small addition of marshalling multiple objects. I hope you understand, I've tried to word my question as cohesively as possible... thank you.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-04-28

To continue, here is my marshal to xml code:

File outFile = new File("itemList2.xml"); 
    FileOutputStream fout = new FileOutputStream(outFile);
    il. marshal(fout);
}finally {