I have a xml document like this rootXMLDoc=<root> <param></param></root>
. I need to insert paramxmlDoc= <parameter par='1'>abc</parameter>
. how to insert paramxmlDoc to rootXMLDoc in java.? and i need output like this
<root>
<parameter par='1'>abc</parameter>
<param></param>
</root>
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Like this:
Element e = paramxmlDoc.getRootElement();
paramxmlDoc.setRootElement(null); // break connection between doc and element
rootXMLDoc.getRootElement().addChild(e); // Insert node in other document
Note: This is from memory, so the actual method calls can be slightly different but you get the idea.