This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adoptNode() and importNode() observation

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I ran into a strange issue. When I used adoptNode() to adopt a node from a different document to another one, it did import the node, but misplaced some data(and inserted some nulls) in the destination document.

The misplaced data was making the destination document to fail when validated with the DTD.

I have fixed the issue by changing the adoptNode() method to importNode().

Below is a sample incorrect XML generated using adoptNode(). See there is a null some how got inserted.


Now my observation is that, when I just print the child nodes of the node I am adopting, the issue gets resolved and adoptNode() works fine.



The commented one line importNode() code is the one I actually have. When I comment that, and by using the code from for loop till adoptNode() the issue does not occur.

This is not actually a question... just wanted to share the behavior I noticed...

Thanks much!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic