dom4j的org.dom4j.IllegalAddException处理

来源:互联网 发布:域名在哪里备案 编辑:程序博客网 时间:2024/06/09 11:00
org.dom4j.IllegalAddException: The node "your node description..." could not be added to the element "yourNode" because: The Node already has an existing parent of "yourNode" 


Document  doc = DocumentHelper.createDocument();

Element   root = doc.addElement("config")

Element   files = root.addElement("files");

String configFiles="<files><file name="AdShower123.exe" oriname="update\adshower123.zip" ver="1.0.0.1" md5="" update="http://soft.51cy.org:80/adv/package/adshower.zip" action="3" param="" op="0" optype="3" opcmd="$(appdir)\AdShower.exe" opparam=""/><file name="AdShower123.exe" oriname="update\adshower123.zip" ver="1.0.0.1" md5="" update="http://soft.51cy.org:80/adv/package/adshower.zip" action="3" param="" op="0" optype="3" opcmd="$(appdir)\AdShower.exe" opparam=""/></files>";


Document fileDom=DocumentHelper.parseText(configFiles);
//root.add(fileDom.getRootElement());
//System.out.println("2222222222:"+fileDom.selectNodes("files").toString());
for (Iterator iterator = fileDom.getRootElement().elementIterator(); iterator.hasNext();) {
  Element e = (Element) iterator.next();
  // files.add(e);
 files.add((Element)e.clone());
}

红色是出错的位置,蓝色为正确的写法

参考链接:http://moon-cake.iteye.com/blog/298052

原创粉丝点击