• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
reema duggal
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
anupv
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic