title: Delete Xml data using php
body: <p>How can I delete specific elements on xml using php</p>
  
  <p>my.xml</p>
  
  <pre><code>    &lt;usr&gt;
          &lt;uid trk= "1234"&gt;
              &lt;deleteThis&gt;
                  &lt;mychild&gt;here&lt;/mychild&gt;
                  &lt;anotherchild&gt;here&lt;/anotherchild&gt;
              &lt;/deleteThis&gt;
          &lt;/uid&gt;
      &lt;/usr&gt;
  </code></pre>
  
  <p>I want to remove the "deleteThis" element and its children</p>
  
  <p>result:</p>
  
  <pre><code>     &lt;usr&gt;
          &lt;uid trk= "1234"&gt;
          &lt;/uid&gt;
      &lt;/usr&gt;
  </code></pre>
  
  <p>here's my non-working code</p>
  
  <p>index.php</p>
  
  <pre><code>$xml = new DOMDocument; 
      $xml-&gt;load('my.xml');
      $thedocument = $xml-&gt;documentElement;
      $list = $thedocument-&gt;getElementsByTagName('uid');
  
      foreach ($list as $domElement){
        $attrValue = $domElement-&gt;getAttribute('trk'); 
        if ($attrValue == "1234") { //if &lt;uid trk= "1234"&gt;
          $valY = $domElement-&gt;getElementsByTagName('deleteThis');
          $thedocument-&gt;removeChild($valY);
        }
      }
  $xml-&gt;save("my.xml");
  </code></pre>
  
  <p>It seems it doesn't found the node.</p>