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!

    Here's the solution:

    That pesky line of code must be rewritten:

    $result->item(0)->parentNode->removeChild($result->item(0));

      Nevermind, that change was not correct

        Write a Reply...