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。 –