Call to a member function addChild() on a non-object PHP
I get this error Call to a member function addChild() on a non-object, but
the XML file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<urlset>
<url>
<loc>http://mysite.com/</loc>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
</urlset>
And I'm doing this:
//APPEND TO SITEMAP
$file = '../sitemap.xml';
$xml = simplexml_load_file($file);
$urlset = $xml->urlset;
$urls = $urlset->addChild('url');
$urls->addAttribute("mongoID", $theAuthorUniqueMongoID);
$urls->addChild('loc', 'http://mysite.com/author/'.$authorLink.'/');
$urls->addChild('changefreq', 'monthly');
$urls->addChild('priority', '0.80');
$xml->asXML($file);
I'm basically just appending some stuff to my site map. I was never any
good at XML but I'm not sure what I'm doing wrong on this one. Googled the
error and I tried a few of their suggestions but nothing that got me a
different error. Any help would be awesome!
No comments:
Post a Comment