1

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>

3
  • Which Java XML parser/generator library do you use? There are many such libraries, so the answer depends on the library that you use. For example do you use a DOM or SAX XML library? Commented Jun 16, 2010 at 17:47
  • Shouldn't you consider deleting this question since you asked a slight variation of the same question shortly after? (See stackoverflow.com/questions/3042592/…) Commented Jun 16, 2010 at 17:59
  • But the answers for both of my similar questions are different. So I didnt consider to delete this one. May be it ll be useful for someone in future. Commented Jun 17, 2010 at 5:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.