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.