createdXml

private static void createXml(){

try {
Document document = DocumentHelper.createDocument();
Element root = document.addElement("users");

root.addElement("user").addAttribute("id", "001").addElement("uname").addText("zs01");
root.addElement("user").addAttribute("id", "002").addElement("uname").addText("zs02");
OutputFormat format = new OutputFormat("");
format.setNewlines(true);
format.setEncoding("gbk");
OutputStream out = new FileOutputStream("d:/users.xml");
XMLWriter xmlWriter = new XMLWriter(out, format);
System.out.println(document);
xmlWriter.write(document);
xmlWriter.flush();
xmlWriter.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

你可能感兴趣的:(xml)