wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes adoptNode() and importNode() observation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "adoptNode() and importNode() observation" Watch "adoptNode() and importNode() observation" New topic
Author

adoptNode() and importNode() observation

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
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.
 
subject: adoptNode() and importNode() observation
 
Similar Threads
Problems converting a node to string
How to build xml document from Database
XML Parser issue
Appending an new node from one Document to some another document.
Overwriting a specific XML section