File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Put a node into a new xml document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Put a node into a new xml document" Watch "Put a node into a new xml document" New topic

Put a node into a new xml document

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303

I have a node like this:

<A a="a" b="b">
<B c="c"/>
<C d="d"/>

I need to write this entire node into a new xml document in the placeholder as follows:

<xml prologue>
<!-- place for the above node -->

I am using DOM as the parser. Any ideas on how this can be done.
I tried using root.importNode(), however, it appends only
<A a="a" b="b"> and misses the rest of the child nodes.

Plez help!!!

SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Hasan Pasha

Joined: Feb 23, 2005
Posts: 25
Check out the following method in the Node Interface (org.w3c.dom)

API documentation:
Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
I agree. Here's the link:
subject: Put a node into a new xml document