日期:2014-05-20 浏览次数:20671 次
public class TestDom4j {
public static void main(String[] args) throws DocumentException {
File file = new File("Test/NewFile.xml");
SAXReader saxReader = new SAXReader();
Document document = (Document) saxReader.read(file);
document.getRootElement().addElement("first");
}
}
OutputFormat format = OutputFormat.createPrettyPrint();
// 指定XML编码
format.setEncoding("UTF-8");
XMLWriter writer = new XMLWriter(new FileOutputStream("Test/NewFile.xml"), format);
writer.write(document);
writer.close();