I have an xml file of this structure
<?xml version="1.0" encoding="iso-8859-1"?> <my_events> <event id="e20111129215359"> <title>the title</title> <channel id="1"> <name>A name</name> <onclick></onclick> </channel> <event_site> <name/> <url/> </event_site> <start_date>Thu Mar 08 2012</start_date> <start_time>11:00 AM</start_time> <end_date>null</end_date> <end_time>null</end_time> <notes>Notes for the event</notes> </event> </my_events> To delete an event, I have this php function.
<?php include_once("phpshared.php"); function delete_event( $nodeid ) { $nodes = new SimpleXMLElement('my_events.xml', LIBXML_NOCDATA, true); $node = $nodes->xpath("/my_events/event[@id='$nodeid']"); $node->parentNode->removeChild($node); $formatted = formatXmlString($nodes->asXML()); $file = fopen ('my_events.xml', "w"); fwrite($file, $formatted); fclose ($file); } echo delete_event(trim($_REQUEST['nodeid'])); ?> That doesn't delete the node. Is there a different way to do this?