/**
* 生成xml文档
*
* @param doc
* @param filename
* @throws UnsupportedEncodingException
*/
public static void createXML(Document doc, String filename) throws UnsupportedEncodingException {
// 生成XML
OutputFormat format = OutputFormat.createPrettyPrint();// 格式
format.setEncoding(doc.getXMLEncoding());
format.setNewLineAfterDeclaration(false);//解决声明下空行问题
XMLWriter writer = new XMLWriter(format);
File xmlfile = new File(filename);
try {
FileOutputStream out = new FileOutputStream(xmlfile);
writer.setOutputStream(out);
writer.write(doc);
writer.flush();
writer.close();
System.out.println("生成文件" + filename + "...");
}
catch (IOException e) {
e.printStackTrace();
xmlfile.delete();
}
}