title: Alternately getting the error (Extra content at the end of the document )
body: <p>I am getting error while loading the xml file. I got many answers related to the topic but I really could not find why this error maybe coming in my file.</p>
  
  <pre><code>Warning: DOMDocument::load() [&lt;a href='domdocument.load'&gt;domdocument.load&lt;/a&gt;]: Extra content at the end of the document 
  </code></pre>
  
  <p>When I am running the file, it runs successfully, but when I reload it, it gives the above error instead of adding another node. But, next time when I reload it runs successfully again. This is happening alternatively. Please someone tell me why is this happening and how to solve the problem.</p>
  
  <p>I am using this php code to edit the xml file:</p>
  
  <pre><code>&lt;?php
  $dom = new DomDocument("1.0", "UTF-8");
  $dom-&gt;load('filename.xml');
  
  $noteElem = $dom-&gt;createElement('note');
  $toElem = $dom-&gt;createElement('to', 'Chikck');
  $fromElem = $dom-&gt;createElement('from', 'ewrw');
  
  $noteElem-&gt;appendChild($toElem);
  $noteElem-&gt;appendChild($fromElem);
  
  $dom-&gt;appendChild($noteElem);
  $dom-&gt;formatOutput = TRUE;
  //$xmlString = $dom-&gt;saveXML();
  //echo $xmlString;
  $dom-&gt;save('filename.xml');
  ?&gt;
  </code></pre>
  
  <p>This is the xml file I am editing:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;note&gt;
    &lt;to&gt;Chikck&lt;/to&gt;
    &lt;from&gt;ewrw&lt;/from&gt;
  &lt;/note&gt;
  </code></pre>