title: Uncaught exception 'DOMException' with message 'Hierarchy Request Error'
body: <p>I'm getting error while replacing or adding a child into a node.</p>
  
  <p>Required is :</p>
  
  <p>I want to change this to..</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;contacts&gt;
    &lt;person&gt;Adam&lt;/person&gt;
    &lt;person&gt;Eva&lt;/person&gt;
    &lt;person&gt;John&lt;/person&gt;
    &lt;person&gt;Thomas&lt;/person&gt;
  &lt;/contacts&gt;
  </code></pre>
  
  <p>like this </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;contacts&gt;
    &lt;person&gt;Adam&lt;/person&gt;
    &lt;p&gt;
        &lt;person&gt;Eva&lt;/person&gt;
    &lt;/p&gt;
    &lt;person&gt;John&lt;/person&gt;
    &lt;person&gt;Thomas&lt;/person&gt;
  &lt;/contacts&gt;
  </code></pre>
  
  <p>error is</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'DOMException' with message 'Hierarchy Request Error'</p>
  </blockquote>
  
  <p>my code is</p>
  
  <pre><code>function changeTagName($changeble) {
      for ($index = 0; $index &lt; count($changeble); $index++) {
          $new = $xmlDoc-&gt;createElement("p");
          $new -&gt;setAttribute("channel", "wp.com");
          $new -&gt;appendChild($changeble[$index]);
          $old = $changeble[$index];
          $result = $old-&gt;parentNode-&gt;replaceChild($new , $old);
      }
  }
  </code></pre>