Editing to specify more clearly the scenario.
I have to write a xml file, the info comes from several beans (not even whole bean, jsut subset of some of them), some of the beans contain lists etc. So I cannot just give xstream one root bean and let it write the xml. Also some formatting might need to fulfill some conditions, but the previous issue is the one
Right now I am using JDOM to create the doc in memory, and eventually I use a XMLOutputter to write the doc to a file.
But the beans I want to write can have very large lists of other beans etc, and the memory used can be quite high.
So I suspect there should be a better way in terms of memory?
I already create the xml for some beans inside the larger bean with xstream and append them as Elements to the JDOM.
I was hoping the same way its more memory efficient to parse xml using a pull parser, the same could be apply to writing xml.
Let me get this straight:
You start off with a tree of beans. You wish to use these to construct an XML document following their structure but with its own syntax/schema so simple bean XML serialization is out of the question…
If that is so, JAXB as recommended by Blaise Doughan is a good suggestion. If, however, you require a much finer control over the XML formatting, you need to do some highly specific serialization, or perhaps you wish to remove some bean references while creating the XML to allow garbage collection during the execution, then the Streaming API for XML (StAX) might be what you need. You can write XML constructs to a stream with it.
http://download.oracle.com/javase/6/docs/api/javax/xml/stream/package-summary.html
Sorry if it isn’t exactly what you meant. If I’m getting it wrong, could you give us a small usage scenario?