解决Dom4j中"The Node already has an existing parent"有关问题

解决Dom4j中The Node already has an existing parent问题??常常需要在两个Document中互相复制Element,

解决Dom4j中"The Node already has an existing parent"问题

?

?

常常需要在两个Document中互相复制Element,可是Dom4j中使用Element.add(Elemnet)方法就会出现出题的错误:

?

"The Node already has an existing parent"

?

?

查看AbstractElement.java的源码,得到解决办法:调用Element的clone()方法。

?

?

Element allAdd = (Element)add.clone();

xaldoc.getRootElement().add(allAdd);