alittee Posted September 7, 2012 Share Posted September 7, 2012 This is driving me up the wall what causes this to happen? /*CREATING XML DOCUMENT*/ $doc = new DOMDocument('1.0'); //creating document format $doc->formatOutput = true; $doc->load($patXML); //root node - policies $pols = $doc->getElementsByTagName('Policies')->item(0); //child node - policy $policy = $doc->createElement('Policy'); $pols->appendChild($policy); Just want to add another element to the XML file. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/268114-fatal-error-call-to-a-member-function-appendchild/ Share on other sites More sharing options...
alittee Posted September 7, 2012 Author Share Posted September 7, 2012 Sorrry the Error I'm receiving is Fatal error: Call to a member function appendChild() on a non-object on line.... Quote Link to comment https://forums.phpfreaks.com/topic/268114-fatal-error-call-to-a-member-function-appendchild/#findComment-1376010 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 the item() call will return NULL if there is no item at that index. $pols = $doc->getElementsByTagName('Policies')->item(0); if($pols == NULL){ die('No element found'); }else{ $policy = $doc->createElement('Policy'); $pols->appendChild($policy); } Quote Link to comment https://forums.phpfreaks.com/topic/268114-fatal-error-call-to-a-member-function-appendchild/#findComment-1376030 Share on other sites More sharing options...
alittee Posted September 8, 2012 Author Share Posted September 8, 2012 THANK YOU SOOOO MUCH! but how did that work??? seems like it would have just been something that tests if it was working not necessarily a fix to the problem??? Either way thank you a lot, I may have ended up breaking something. Quote Link to comment https://forums.phpfreaks.com/topic/268114-fatal-error-call-to-a-member-function-appendchild/#findComment-1376294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.