title: SimpleXML error 'Call to a member function on a non-object'
body: <p>I keep getting the following error:</p>
  
  <blockquote>
    <p>Fatal error: Call to a member function addChild() on a non-object in /www/zzl.org/t/h/e/theseminary/htdocs/submit.php on line 3</p>
  </blockquote>
  
  <p>My code, in its own php file, is as follows:</p>
  
  <pre><code>&lt;?php
  $xmlobject = simplexml_load_file('data.xml');
  $xmlobject[0]-&gt;channel[0]-&gt;posts[0]-&gt;addChild("item");
  $itemcount = $xmlobject-&gt;channel-&gt;posts-&gt;count();
  $xmlobject-&gt;channel[0]-&gt;posts[0]-&gt;item[$itemcount]-&gt;addChild("title", $title);
  $xmlobject-&gt;channel-&gt;posts-&gt;item[$itemcount]-&gt;addChild("content", $content);
  $xmlobject-&gt;asxml("data.xml");
  header( "Location: $url" );
  ?&gt;
  </code></pre>
  
  <p>I realize this question has been asked multiple times, but I could not find a solution to <em>my</em> problem.</p>
  
  <p>Here's the XML file, if it helps.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;channel&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;description&gt;&lt;/description&gt;
  &lt;posts&gt;
  &lt;/posts&gt;
  &lt;/channel&gt;
  </code></pre>