File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "adoptNode() and importNode() observation" Watch "adoptNode() and importNode() observation" New topic

adoptNode() and importNode() observation

John Jai

Joined: May 31, 2011
Posts: 1776

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!!!
I agree. Here's the link:
subject: adoptNode() and importNode() observation
jQuery in Action, 3rd edition