I'm struggling with what I feel should be easy. Basically, I have one DOM that I'm traversing. When I get to a particular Node I'd like to create a separate Document from this Node, so that it's a brand new Document. If I could do that with a particular Nodes' children even better, but for now, stick to the simple example.
Maybe code would help understand what I'm try to do..
// we have some responseElem somewhere in the original document
Node rootOfNewDocument = responseElem.getFirstChild();
// now i want this rootOfNewDocument to be the root of a new Document ... how do i do this?
// this isn't exactly what i want, nor does it work (complains HIERARCHY_REQUEST_ERR: An attempt was
// made to insert a node where it is not permitted. )
Document responseDoc = builder.newDocument();
Node importedNode = responseDoc.importNode(rootOfNewDocument , true);
responseDoc.appendChild(importedNode);
Is there something simple I'm missing? Can I clone the node and then set it to a Document type somehow? Any help would be must appreciated. Of course, if there's a better place to post a question of this kind, please refer me. Thanks.