Java: Saving StreamResult to a file
I am not familiar with the API... but does this link give you what you are after?
Transformer transformer = TransformerFactory.newInstance().newTransformer();transformer.setOutputProperty(OutputKeys.INDENT, "yes");//initialize StreamResult with File object to save to fileStreamResult result = new StreamResult(new StringWriter());DOMSource source = new DOMSource(doc);transformer.transform(source, result);String xmlString = result.getWriter().toString();System.out.println(xmlString);