*
The moose likes XML and Related Technologies and the fly likes Appending an new node from one Document to some another document. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Appending an new node from one Document to some another document." Watch "Appending an new node from one Document to some another document." New topic
Author

Appending an new node from one Document to some another document.

reema duggal
Greenhorn

Joined: Mar 13, 2001
Posts: 6
I am trying to Append an new node from one Document to some another document.But appendChild() method was not working.
I am getting a runtime exception:-
com.sun.xml.tree.DomEx: That node doesn't belong in this document.
at com.sun.xml.tree.ParentNode.checkDocument(ParentNode.java:264)
at com.sun.xml.tree.ParentNode.appendChild(ParentNode.java:347)
I found a solution by using importNode() method which is avialable in JAXP1.1
Is there any solution for above mentioned problem in JAXP1.0??
Steffen Foldager
Ranch Hand

Joined: Mar 22, 2001
Posts: 58
The DOM specification from W3C states that you can't append nodes from one Document into another. This has to do with - I think - Document security and integrity especially on the web.
I tried to do the same once, and I ended up making a little contructing method, that extracted the useful information. This also made it clear to me that there was something conceptually not quite rigth with what I was doing, so maybe there's a reason for the restriction.


Steffen Foldager<p>Sun Certified Java Programmer<br />Sun Certified Web Component Developer
anupv
Greenhorn

Joined: Aug 28, 2002
Posts: 3
You need to change node owner to the new docment.
Refer to API
http://www.doc.ic.ac.uk/~sjn5/xml-tr2/docs/api/index.html
Steps
1. Read origienal document to which you want to appent node.
2. Read xml document, elements from which are to be appended to the document in step 1 above. Find element to be appended to the document in step 1 above
3. Using document object in step 1 change node owner of the node
e.g. xmlDoc.changeNodeOwner(docElement);
4. Now add node in step 3 to element from document in step1
Regards
Anup
Nitin Mehta
Greenhorn

Joined: Apr 17, 2003
Posts: 3
Have a look at the org.w3c.dom.Document Class's
importNode method. This method is designed for this purpose only. The method returns a node which has no parent presently but is owned by the document with whose refrence you would have called the method. After this you can attch this new node to the desired location in your tree.
 
Consider Paul's rocket mass heater.
 
subject: Appending an new node from one Document to some another document.
 
Similar Threads
How to remove #text elements (white spaces) from a org.w3c.dom.Element
ParserImpl for DOM
Appending part XML to main XML
Strange error from xerces 2_7_1
adoptNode() and importNode() observation