case ELEMENT_NODE :
// append the node to the other tree
// do nothing
@dhrubo: OK, in that case I have no clue what you're trying to do. I suggest that you edit your post to include a complete, compilable example. Then show input, actual output, and expected output. One thing that I can assure you, however: it is not a problem with the API.
And where do you define dom? When I say "compiles," I mean that I can copy your post into an editor window and actually compile it. As it stands, I can't do that. And seeing you do things like dom.getParentNode().appendChild(), where dom is almost certainly a Document, neither can you.
Edited , please let me know if you need any further clarifications, and note the above code compiles. I am currently working with this code, I have just changed my variables.
First, I'm surprised that you don't get an exception with your importNode() call, since you're importing the Document, which shouldn't be allowed (per the JavaDoc).
I am extremely SORRY, missed couple of line codes from a method. I think everything should be fine now for compilation.
No, importNode is returning the node, and if I add the parent noe i.e. <dhruba> instead of trying to add it's child nodes, it is adding fine and generating well formed output , but with <dhruba> parent element which I don't want. In addition, I need all type of nodes , TEXT_NODE or ELEMENT_NODE , so I didn't use the check, and surprisingly, it is returning null for either one of the node type according to given input.
Now to the question that you asked: if you only want to attach specific node types, you need to make a test using the node's type. A switch statement is the easiest (note: this has not been compiled, may contain syntax errors):