Here you can find the source of createDocumentFromResult( final StreamResult result)
public static Document createDocumentFromResult( final StreamResult result)
//package com.java2s; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { /**/*from w w w .j av a 2 s . co m*/ * returns Document from StreamResult */ public static Document createDocumentFromResult( final StreamResult result) { Document document = null; final String fileString = result.getWriter().toString(); try { final DocumentBuilder parser = DocumentBuilderFactory .newInstance().newDocumentBuilder(); final StringReader reader = new StringReader(fileString); final InputSource inputSource = new InputSource(reader); document = parser.parse(inputSource); } catch (final SAXException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final ParserConfigurationException e) { e.printStackTrace(); } return document; } }