首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-08-27 
解决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);

热点排行