1
我嘗試將文檔保存到XML中相當輸出。但問題是每個新元素都從前一個元素結束標記行開始。JAVA 8 xml漂亮的輸出不能正常工作
例子:
<?xml version="1.0" encoding="UTF-8"?><report>
<jiraentry category="SERVICE & ASSET" component="DOCMAN" priority="10" summary="Bug Generated By, UNCHECKED_ACCESS">Tool:UNCHECKED_ACCESS Date:2015-11-12
</jiraentry>
你可以看到和文字打印在透水line.Here是下面這在我以前使用的變壓器,以保存XML我的Java代碼。
//normalize the xml file
root.getDocumentElement().normalize();
//remove standalone no
root.setXmlStandalone(true);
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", new Integer(0));//add intend to the new line
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource source = new DOMSource(root);
StreamResult result = new StreamResult(new OutputStreamWriter(new FileOutputStream(this.outpath), "UTF-8"));//save the file
transformer.transform(source, result);
任何人都可以建議我讓這個更漂亮和清晰。
貴原始XML包含換行符? – ThomasRS
他們沒有東西會調用原始的xml,程序通過轉換根來創建xml。 –