将document写入xml文档

1.文档中全为英文,不设置编码,直接写入的形式.  
XMLWriter writer = new XMLWriter(new  FileWriter("output.xml"));
writer.write(document);
   writer.close();

2.文档中含有中文,设置编码格式写入的形式.
OutputFormat format = OutputFormat.createPrettyPrint();
// 指定XML编码
format.setEncoding("GBK");
XMLWriter writer = new XMLWriter(newFileWriter("output.xml"),format);
writer.write(document);
writer.close();

你可能感兴趣的:(xml)