XML : Remove XML element with PHP

I want to remove the element of the XML file under certain condition:

example.xml:

  <all>  - <item>    <ProductID>46121</ProductID>     <Price1>50</Price1>     </item>  - <item>    <ProductID>51151</ProductID>     <Price1>20</Price1>     </item>  </all>    

php:

  <?php  $xml = simplexml_load_file('example.xml');  foreach ($xml->item as $item) {  $price  = $item->Price1;  if ($price < 50 ) { REMOVE THIS ITEM  }   }  $xml->asXML("result.xml");  ?>    

I want if the price is less than 50 REMOVE THIS ITEM

result.xml to be:

  <all>  - <item>    <ProductID>46121</ProductID>     <Price1>50</Price1>     </item>  </all>    

No comments:

Post a Comment