Removing a node from xml file

Kazuya17

New Member
I have an xml file \[code\]<?xml version="1.0"?><category> <name>SWEATERS</name> <name>WATCHES</name> <name>PANTS</name> <name>test</name> <name>1</name></category>\[/code\]How i can remove the node \[code\]<name>test</name>\[/code\] using xpath ,xquery and php. I used this code \[code\] $name='test; $xmlfile="config/shop_categories.xml"; $xml = simplexml_load_file($xmlfile); $target = $xml->xpath('/category[name="'.trim($name).'"]'); print_r($target[0]); if($target == false) return; $domRef = dom_import_simplexml($target[0]); //Select position 0 in XPath array $domRef->parentNode->removeChild($domRef); $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml->asXML()); $dom->save($xmlfile);\[/code\]But it is not working.
 
Back
Top