Anybody have any idea why this code would produce the "Trying to get property of non-object" error?
<?php
$NewsTitleID = $_POST['NewsTitleID'];
$source = 'news_new.xml';
$dom = new DomDocument();
$dom->load($source); //Loads Xml document
$NewsTitleID = $NewsTitleID - 1; //Used to align id number and the xpath numbering
$xpath = new DomXPath($dom); //Defines the path to each node
$result = $xpath->query("//event");
$result->item($NewsTitleID)->parentNode->removeChild($result->item($NewsTitleID));
$dom->save($source);
include ("../inc_functions.php");
delxlines($source, 1);
?>
I've inherited this code that is a form that deletes nodes from an XML file. The error says it's coming from this line:
$result->item($NewsTitleID)->parentNode->removeChild($result->item($NewsTitleID));
Any help would be greatly appreciated. Thanks!