public void getXMLWrite(Document document, String filePath) throws Exception { OutputFormat of = new OutputFormat(" ", true); of.setEncoding("UTF-8"); XMLWriter xw = new XMLWriter(new FileWriter(filePath), of); xw.setEscapeText(false); xw.write(document); xw.close(); System.out.println(document.asXML()); }