You can build an XML DOM in memory and then write it out to an XML
string. It's a bit tedious but certainly something that people do all the time. Scroll on down to the XML forum on the ranch and ask for pointers to some introductory examples.
You have your choice of the W3C DOM defined in the
Java APIs or some simpler alternatives. JDom was invented just to make things easier for Java folks.
You can also just build XML as a giant StringBuffer. At first this seems easier to follow because you don't have to learn your way around the DOM, but after a certain level of complexity keeping track of the structure in a string gets difficult, too.
Any of that sound on target to your question?