title: Correctly deleting child elements in PHP using DOMDocument and DOMXPath
body: <p>This was previous another question, but we won't talk about that. I am isolating a number of sections in a third party HTML document. When matching some, I need to remove certain tags from the result. The code I found for this on SO was:</p>
  
  <pre><code>$name = $xpath-&gt;query("//div[@class='leftColBig']//h3")-&gt;item(0);
  // remove &lt;span&gt;
  foreach($xpath-&gt;query("//span", $name) as $node)
      $node-&gt;parentNode-&gt;removeChild($node);
  </code></pre>
  
  <p>This has the unfortunate side effect of not just deleting the child from $name, but the entire DOMDocument :( How can I isolate the removeChild just to the section I found using the query.</p>