日期:2014-05-17  浏览次数:20674 次

xml如何把一个节点添加到别的节点下
用dom4j
先读入了一个xml
Document document = reader.read(new File("c:/try.xml"));
Element root = document.getRootElement(); 
Element e = root.element("b");

Document document2 = DocumentHelper.createDocument();
Element root2 = document2.addElement("root2");
root2.add(e);//这句不对
XMLWriter output = new XMLWriter(new FileWriter( "c:/try2.xml"));
output.write(document2);

------解决方案--------------------
用xpath