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;
  }
}

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 ; } }
convert a document to a string , assuming later encoding to utf - 8 .
