0

so i need to remove an element from an XML file using PHP. After some googling i found this question which i think put me on the right track. However when I run the code to delete the element, nothing happens. I don't get any error messages, and the node i have tried to delete is still there.

function deleteCourse($course){
echo "beginning delete";
$xml = self::getxml(); # get the XML file
$theCourse = $xml->xpath('course[name = "'.$course.'"]');
echo self::toJSON($theCourse[0]);
unset($theCourse[0]);

$xml->asXml("data.xml");
}

I've looked at the question I linked to and cannot see where i have gone wrong. Can anybody help me?

Community
  • 1
  • 1
Jamie McAllister
  • 729
  • 2
  • 11
  • 33
  • 2
    You found that question by googling? Not because I closed your previous question as a duplicate of it? – Barmar Apr 09 '15 at 11:11
  • no, i had found that question yesterday, which led me to the problem on the last question i posted. now this is another issue haha... hopefully the last issue – Jamie McAllister Apr 09 '15 at 11:18
  • The question you linked answers your question. Read it carefully and don't unset the array element but the self reference. – ThW Apr 09 '15 at 11:34
  • okay i see it now, i didn't realise `list` was necessary, thanks – Jamie McAllister Apr 09 '15 at 11:37

0 Answers0