title: Simple XML Call to a member function addChild() on boolean
body: <p>I have a problem composing XML sitemap using <strong>simple xml PHP function</strong>, having <em>almost equal situation</em> and when <code>sitemap</code> tag, it is not working:</p>
  
  <pre><code>$xml = simplexml_load_string('&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;&lt;/urlset&gt;');
  
  $sitemap = $xml-&gt;addChild("sitemap");
  $sitemap-&gt;addChild("loc", "http://www.example.com/sitemap-1.xml");
  </code></pre>
  
  <blockquote>
    <p>Fatal error:  Call to a member function addChild() on boolean</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/MSvIH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MSvIH.png" alt="enter image description here"></a></p>
  
  <p>This is <strong>working</strong> <strong>reliably</strong>:</p>
  
  <pre><code>$xml = simplexml_load_string('&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;&lt;/urlset&gt;');
  
  $url = $xml-&gt;addChild("url");
  $url-&gt;addChild("loc", "http://www.example.com/sitemap-2.xml");
  </code></pre>