public static String documentToString ( Document xmlDocument ) throws IOException { String encoding = ( xmlDocument . getXmlEncoding ( ) == null ) ? "UTF-8" : xmlDocument . getXmlEncoding ( ) ; OutputFormat format = new OutputFormat ( xmlDocument ) ; format . setLineWidth ( 65 ) ; format . setIndenting ( true ) ; format . setIndent ( 2 ) ; format . setEncoding ( encoding ) ; try ( Writer out = new StringWriter ( ) ) { XMLSerializer serializer = new XMLSerializer ( out , format ) ; serializer . serialize ( xmlDocument ) ; return out . toString ( ) ; } }
Returns a String representation for the XML Document .