question: public static String toString ( Document hostDoc ) throws IOException { try { StringWriter out = new StringWriter ( ) ; DOMSource domSource = new DOMSource ( hostDoc ) ; StreamResult streamResult = new StreamResult ( out ) ; TransformerFactory tf = TransformerFactory . newInstance ( ) ; Transformer serializer = tf . newTransformer ( ) ; serializer . setOutputProperty ( OutputKeys . ENCODING , ENC . name ( ) ) ; serializer . setOutputProperty ( OutputKeys . METHOD , "html" ) ; serializer . setOutputProperty ( OutputKeys . INDENT , "no" ) ; serializer . setOutputProperty ( OutputKeys . DOCTYPE_PUBLIC , HtmlDomUtil . HTML_STRICT ) ; serializer . transform ( domSource , streamResult ) ; return out . toString ( ) ; } catch ( TransformerException e ) { IOException r = new IOException ( "Error transforming page" ) ; r . initCause ( e ) ; throw r ; } }
target:  Convert a document to a String, assuming later encoding to UTF-8. 