首先要下载对应的jar包,其中dom4j.jar,jaxen.jar
如创建例子
:Document document = DocumentHelper.createDocument();
Element root = document.addElement("tree");
root .addAttribute("id", "0");
root.addComment("this is a newspaper xml"); //注释文件
root.addProcessingInstruction("MsgHeader", "text");
Element item=root.addElement("item");
item.addAttribute("text", "工作台");
item.addAttribute("id", "1");
Element subelement=item.addElement("item");
subelement.addAttribute("text", "代办事项");
subelement.addAttribute("id", "2");
subelement=item.addElement("item");
subelement.addAttribute("text", "代办事项2");
subelement.addAttribute("id", "3");
Element litelement=subelement.addElement("item");
litelement.addAttribute("text","代办事项2-1" );
litelement.addAttribute("id", "301");
String content=document.asXML();
System.out.println(content);