DOM4J 操作 XML 时抛出 org.dom4j.IllegalAddException 的异常的解决方案

来源:互联网 发布:ps cs6 删除元数据 编辑:程序博客网 时间:2024/05/14 23:40

如果你在使用 dom4j 的时候出现了下面这个异常:

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" 

那么你肯定是用的 myelement.add(needAddElement); 只要稍微改一下就可以了,把  needAddElement 改为 (Element)needAddElement.clone() 就可以了。

即修改为:myelement.add((Element)needAddElement.clone());

原创粉丝点击