Why can't you just do:
String result = dom.toXML().toString();
If you want to do it the long way, then you use a TransformerFactory to transform the DOM to anything you want. First thing you do is wrap your Document in a DOMSource
DOMSource domSource = new DOMSource(document);
Prepare a StringWriter so we can route the stream to a String:
StringWriter writer = new StringWriter();
StreamResult streamResult = new StreamResult(writer);
Prepare a TransformationFactory so you can transform the DOM to the source provided:
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory .newTransformer();
transformer.transform(domSource, streamResult);
Finally, you get the String:
String result = writer.toString();
Hope that helped!
asXml()
doesn't work for you? I don't understand what you need, can you clarify your question please? – Terrill