{"id":4185,"date":"2011-07-20T02:48:00","date_gmt":"2011-07-20T02:48:00","guid":{"rendered":""},"modified":"2026-04-18T22:50:39","modified_gmt":"2026-04-18T22:50:39","slug":"wrong_document_err-a-node-is-used-in-a-different-document-than-the-one-that-created-it","status":"publish","type":"post","link":"https:\/\/hellem.org\/wblog\/?p=4185","title":{"rendered":"WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it"},"content":{"rendered":"<p>Spent hours struggling with the stupid error &#8220;WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it&#8221;. I have two XML-documents one, which I need to copy a given node from and the other file where I first needed to remove the matching node then copy it from source to the target file. Trick is to use importNode, not just cloneNode<\/p>\n<p><code><br \/>\ndef copyOfSource = sourceProviders[0].cloneNode(true)<br \/>\ntargetRoot.appendChild(targetDoc.importNode(copyOfSource, true))<br \/>\n<\/code><\/p>\n<p>Hours of work solved in few minutes just refining my Google search. Was about to post a question on http:\/\/stackoverflow.com and while preparing the question I needed some more background information. Tada&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spent hours struggling with the stupid error &#8220;WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it&#8221;. I have two XML-documents one, which I need to copy a given node from and the other file where I first needed to remove the matching node then copy it from source to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-4185","post","type-post","status-publish","format-standard","hentry","category-c18"],"_links":{"self":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4185"}],"version-history":[{"count":1,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4185\/revisions"}],"predecessor-version":[{"id":13420,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4185\/revisions\/13420"}],"wp:attachment":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}