title: PHP XML remove element and all children by name
body: <p>I have an XML file structured as:</p>
  
  <pre><code>&lt;root&gt;
    &lt;featured&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;tweet&gt;&lt;/tweet&gt;
      &lt;img&gt;&lt;/img&gt;
    &lt;/featured&gt;
  &lt;/root&gt; 
  </code></pre>
  
  <p>The  element is added dynamically , the user needs the option to remove the  element on certain occasions, </p>
  
  <p>I have tried a few variations of code including:</p>
  
  <pre><code>        $featureddel = $xpath-&gt;query('//featured');
  
  while ( $featureddel-&gt;hasChildNodes()){
  $featureddel-&gt;removeChild($featureddel-&gt;childNodes-&gt;item(0));
  }
  </code></pre>
  
  <p>which gives me a error:</p>
  
  <pre><code>PHP Fatal error: Call to undefined method DOMNodeList::hasChildNodes() 
  </code></pre>
  
  <p>Ive also tried:</p>
  
  <pre><code>$featureddel= $dom-&gt;getElementsByTagName('featured');
  $featureddel-&gt;parentNode-&gt;removeChild($featureddel);
  </code></pre>
  
  <p>which returns:</p>
  
  <pre><code>PHP Fatal error: Call to a member function removeChild() on a non-object
  </code></pre>