title: How do you rename a tag in SimpleXML through a DOM object?
body: <p>The problem seems straightforward, but I'm having trouble getting access to the tag name of a SimpleXMLElement.</p>
  
  <p>Let's say I have the follow XML structure:</p>
  
  <pre><code>&lt;xml&gt;
       &lt;oldName&gt;Stuff&lt;/oldName&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>And I want it to look like this:</p>
  
  <pre><code>&lt;xml&gt;
       &lt;newName&gt;Stuff&lt;/newName&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p><strike>Is this possible to do without doing a copy of the entire object?</strike></p>
  
  <p>I've started to realize the errors of the ways I am approaching this problem.  It seems that I need to convert my SimpleXMLElement into a DOM object.  Upon doing so I find it very hard to manipulate the object in the way I want (apparently renaming tags in a DOM isn't easy to do for a reason).</p>
  
  <p>So... I am able to import my SimpleXMLElement into a DOM object with the import, but I am  finding it difficult to do the clone. </p>
  
  <p>Is the following the right thinking behind cloning a DOM object or am I still way off:</p>
  
  <pre><code>$old = $dom-&gt;getElementsByTagName('old')-&gt;item(0); // The tag is unique in my case
  $new = $dom-&gt;createElement('new');
  
  /* ... some recursive logic to copy attributes and children of the $old node ... */
  
  $old-&gt;ownerDocument-&gt;appendChild($new);
  $new-&gt;ownerDocument-&gt;removeChild($old);
  </code></pre>