title: How to delete and edit specific xml node using PHP?
body: <p>I am practicing on XML and PHP. I can not find out how to delete the whole xml node. Here is my XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;items&gt;
  &lt;playlist_name&gt;Channel List&lt;/playlist_name&gt; 
  &lt;category&gt;
  &lt;category_id&gt;1&lt;/category_id&gt;
  &lt;category_title&gt;HD&lt;/category_title&gt;
  &lt;/category&gt;
  &lt;channel&gt;
  &lt;title&gt;VTC HD1&lt;/title&gt;
  &lt;stream_url&gt;&lt;![CDATA[http://203.162.16.22:80/lives/origin01/vtchd1.isml/vtchd1.m3u8]]&gt;&lt;/stream_url&gt; 
  &lt;logo_30x30&gt;vtchd1.jpg&lt;/logo_30x30&gt;
  &lt;category_id&gt;1&lt;/category_id&gt;
  &lt;/channel&gt;
  &lt;channel&gt;
  &lt;title&gt;VTC HD2&lt;/title&gt;
  &lt;stream_url&gt;&lt;![CDATA[http://203.162.16.22:80/lives/origin01/vtchd2.isml/vtchd2.m3u8]]&gt;&lt;/stream_url&gt; 
  &lt;logo_30x30&gt;vtchd2.jpg&lt;/logo_30x30&gt;
  &lt;category_id&gt;1&lt;/category_id&gt;
  &lt;/channel&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p>And here is the code of two function which I am having problem, delete() and edit() </p>
  
  <pre><code>&lt;?php
  
  function delete_channel()
  {
      $file = "nStream.xml";
      $fp = fopen($file, "rb") or die("cannot open file");
      $str = fread($fp, filesize($file));
  
      $xml = new DOMDocument();
      $xml-&gt;formatOutput = true;
      $xml-&gt;preserveWhiteSpace = false;
      $xml-&gt;loadXML($str) or die("Error");
  
      // original
  //      echo "&lt;xmp&gt;OLD:\n". $xml-&gt;saveXML() ."&lt;/xmp&gt;";
  
      // get document element
      $root   = $xml-&gt;documentElement;
      $fnode  = $root-&gt;firstChild;
  
      //get a node
      $ori    = $fnode-&gt;childNodes-&gt;item(0);
  
      // remove
      $fnode-&gt;removeChild($ori);
  
  //      echo "&lt;xmp&gt;NEW:\n". $xml-&gt;saveXML() ."&lt;/xmp&gt;";
  }
  
  function edit_channel()
  {
      echo 'Go Edit'; 
  }   
  </code></pre>
  
  <p>For the delete_channel(), nothing is deleted when I run that function. I want each time I use that function, one  in xml file ll be deleted.</p>