I have fallen in love with simplexml. It does everything you need to except delete a section of code. I found that out trying to answer this for you. I next went to the old DOMDocument method to delete but had trouble identifying the item number of the section I needed to delete. (There maybe a way of finding this in the doc, but I can't do it.) So I combined the two. First the simplexml to ID the section number by "category == "switch"" or something like it. and then using the dom to delete the section.
I did it by category == "switch" but you can use category == "name". simplexml is easy to use.
PHP Code:
<?php
$xml = simplexml_load_file("products.xml");
$i = 0;
foreach ($xml as $category[])
{
if($category[$i]->category == "switch")
$itemNumber = $i;
$i++;
}
$xmlDOC = new DOMDocument();
$xmlDOC ->load('products.xml');
$YourElement = $xmlDOC->documentElement ;
$Element2Remove = $YourElement->getElementsByTagName('product')->item($itemNumber);
$oldContent = $YourElement->removeChild($Element2Remove);
$xmlDOC->save("temp.xml"); // OR whatever file you want.
?>