• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic