Do you want to create an xml response on the server side for a request made through and XMLHttpRequest? Then I hope this helps..
Check here for a tutorial on StAX. By clicking the link "Next Page" you can navigate to the next page where you will find instructions on how to create an xml document using the StAX API.
As the article points out, the well formedness of documents that you create through this method is not guaranteed. The user has to take care that the document is well formed.
However it could save you a lot of work creating your xml documents this way.
You could use this in few different ways..
You could pass an OutputStreamWriter to XMLOutputFactory.createXMLStreamWriter(java.io.Writer) and use the returned XMLStreamWriter to write to the writer / stream.
Or use a StringWriter and get the string after the writing is done and use it as you wish.
subject: can it be possible to write xml doc into a string variable?