简体   繁体   中英

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

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM