dom4j 复制 添加 并修改 节点
public static void main( String[] args ){XMLReadandWrite mR = new XMLReadandWrite();try {Document document1 = mR.readXMLToDoc("d:/zf/workspace/javaTest/1.xml");Document document2 = mR.readXMLToDoc("d:/zf/workspace/javaTest/2.xml");List items = document1.selectNodes("//root//Item");Document newDOc = DocumentHelper.createDocument();Element root = newDOc.addElement("root");for (Iterator iter = items.iterator(); iter.hasNext();) { Element item = (Element) iter.next(); //root.add(item.detach());//如果无需保留原文档对象 //System.out.println(item);root.appendContent(item.getParent()); //如果必需保留原对象}}List attr_listList = newDOc.selectNodes("//root//Item//attr");for(Object o:attr_listList){Element element = (Element)o;Attribute a = element.attribute("Name");//System.out.println(a.asXML());a.setValue("111111");//System.out.println(a.asXML());}//System.out.println(document1.asXML());//System.out.println(newDOc.asXML());document2.getRootElement().appendContent(newDOc.getRootElement());document2.getRootElement().elements().add(0, (Element)newDOc.selectSingleNode("//root//Item").clone());System.out.println(document2.asXML());} catch (Exception e) {e.printStackTrace();}}