【发布时间】:2013-09-07 13:50:57
【问题描述】:
<?xml version="1.0" encoding="UTF-8"?><Request>
<Id>
这里第一个标签被写入文件,然后是 xml 版本,我需要在下一行写入。如下所示
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Id>
我已经使用下面的代码将xml写入文件,请帮助
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new File(
Constants.xmlLocation
+ Constants.metaDataXmlFileName
+ format.format(calendar.getTime()) + ".xml"));
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "5");
transformer.transform(source, result);
【问题讨论】:
-
它已经回答了,在这里查看这篇文章:stackoverflow.com/questions/139076/…
标签: java xml dom xml-parsing