<?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);