title: The proper use of MSXML replaceChild
body: <p>I'm trying to replace a node in one XML document with a node from another XML document. I'm getting the following error: </p>
  
  <pre><code>Insert position node must be a Child of the node to insert under.
  </code></pre>
  
  <p>This is a simplified version of my XML:
  XMLDOC1</p>
  
  <pre><code>&lt;pages&gt;
    &lt;page id="1"&gt;
       &lt;content&gt;First Document&lt;/content&gt;
    &lt;/page&gt;
  &lt;/pages&gt;
  </code></pre>
  
  <p>The other XML document is the exact same in structure:
  XMLDOC2</p>
  
  <pre><code>&lt;pages&gt;
    &lt;page id="1"&gt;
       &lt;content&gt;Second Document&lt;/content&gt;
    &lt;/page&gt;
  &lt;/pages&gt;
  </code></pre>
  
  <p>I need to replace the page node of the first document with the page node of the second document. My attempt looks like this:</p>
  
  <pre><code>firstNode = xmlDoc1.selectSingleNode("//page[@id=1]")
  secondNode = xmlDoc2.selectSingleNode("//page[@id=1]")
  xmlDoc1.replaceChild(firstNode, oldNode)
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>Solution</strong></p>
  
  <pre><code>firstNode.parentNode.replaceChild(xmlDoc1.importNode(secondNode, true), firstNode)
  </code></pre>