开发者

how to add a xml document to another xml document in java

开发者 https://www.devze.com 2023-01-03 14:13 出处:网络
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 paramxm

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> <p开发者_JAVA百科aram></param> </root>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消