tags:

views:

524

answers:

1
A: 

Try something like this:

Node originalNode = cursor.getDomNode();
Node importNode = document.importNode(originalNode.getFirstChild());
Node otherNode = document.createElement("someOtherInsertedElement");
otherNode.appendChild(importNode);
document.appendChild(otherNode);

So in other words:

  1. Get the DOM Node from the cursor. In this case, it's a DOMDocument, so do getFirstChild() to get the root node.
  2. Import it into the DOMDocument.
  3. Do other stuff with the DOMDocument.
  4. Append the imported node to the right Node.

The reason to import is that a node always "belongs" to a given DOMDocument. Just adding the original node would cause exceptions.

Sietse
fails on importNode:org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation. at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)
Supowski
ah. that's because probable because you're importing a DOMDocument. My bad, I missed that bit. try cursor.getDomNode.getFirstChild()
Sietse
cursor.getDomNode.getFirstChild() helped. thx a lot. pls correct it in your answer (I don't have enough reputation to do it myself:] )
Supowski
done. Good to hear it was useful :)
Sietse
At first (before asking here) I did similar solution to yours, I just missed getFirstChild() :) Sometimes it happens that one small stupid miss make everything wrong...
Supowski