I've been trying to make a PHP script that edits an XML file which is used to change a navigation bar for a website. However, whenever most of the time I run this code, it reports a bunch of errors:\[quote\] Notice: Trying to get property of non-object in /Volumes/web/edit/includes/new-page.php on line 96 Warning: Invalid argument supplied for foreach() in /Volumes/web/edit/includes/new-page.php on line 96 Notice: Indirect modification of overloaded element of SimpleXMLElement has no effect in /Volumes/web/edit/includes/new-page.php on line 110 Fatal error: Call to a member function addChild() on a non-object in /Volumes/web/edit/includes/new-page.php on line 113\[/quote\]Below is the part of the script that I'm having trouble with. Sorry if it's a bit messy or strange, as I am new to XML. All it is supposed to do is get all the children of a certain element, add one more child, sort them alphabetically, and put them back into the XML file.\[code\]$nxml = simplexml_load_file($xmlfile) or die ("Unable to load XML file!");$items = array();foreach ($nxml->$parent->part[$navpartnum]->item as $item1) { //Line 96 $items[] .= "{$item1->title} - {$item1->link}";}$items[] .= "{$title} - {$navpointer}";sort($items);$navparts = array();foreach ( $items as $item2 ) { $itemparts = explode(" - ",$item2); $navparts[$itemparts[0]] = $itemparts[1];}unset($nxml->$parent->part[$navpartnum]->item); //Line 110foreach( $navparts as $akey => $avalue ) { $makeitem = $nxml->$parent->part[$navpartnum]->addChild('item'); //Line 113 $makeitem->addChild('title',$akey); $makeitem->addChild('link',$avalue);}file_put_contents($xmlfile, $nxml->asXML());\[/code\]And here is an example input that the above script gets.\[code\]$xmlfile = "/Volumes/web/nav.xml";$navpartnum = 0;$parent = "about";$title = "Contact";$navpointer = "/about/contact/";\[/code\]And finally, here a sample of the XML file.\[code\]<?xml version="1.0" encoding="utf-8"?><navbar><about parts="2"> <part num="1"> <item> <title>Overview</title> <link>/about/overview/</link> </item> </part> <part num="2"> <item> <title>Activities and Athletics</title> <link>/about/activities_and_athletics/</link> </item> </part></about></navbar>\[/code\]This script worked a few times, but now it just shows the errors I said before. Also I'm using PHP 5.4.10. Any ideas as to what might be the problem?