title: Unable to debug the sitemap error
body: <p>I'm trying to pull data from my database and use them in xml files to generate a sitemap. I want 10 files to be generated in compressed format each containing 10 links.That is, file1 contains 1-10 id's , file2 contains 11-20 id's,......file10 contains 91-100 id's. Below is my code to do that - </p>
  
  <pre><code>&lt;?php
  $xml = new SimpleXMLElement('&lt;xml/&gt;');
  Header('Content-type: text/xml');
  $mysql_con = mysqli_connect("localhost", "root", "password", "cases");
  for ($i = 1; $i &lt;= 10; $i++) {
      $sql = "SELECT * FROM samplecases LIMIT " . 10*($i-1) . ", 10";
      $result = mysqli_query($mysql_con,$sql);
      while($row = mysqli_fetch_array($result)) {
              $url = $xml-&gt;addChild('url');
              $url-&gt;addChild('loc', "http://legalcrystal.com/cases/" .$row['id']. "/" . $row['casename']);
              $url-&gt;addChild('lastmod',  $row['decidedon']);
      }
      $dom = new DOMDocument('1.0');
      $dom-&gt;preserveWhiteSpace = false;
      $dom-&gt;formatOutput = true;
      $dom-&gt;loadXML($xml-&gt;asXML());
      echo $dom-&gt;saveXML();
      $dom-&gt;save('/var/www/html/es/sitemap/case-'.$i .'.xml');
      $file = "/var/www/html/es/sitemap/case-".$i .".xml";
      $gzfile = "/var/www/html/es/sitemap/case-" .$i .".gz";
      $fp = gzopen ($gzfile, 'w9');
      gzwrite ($fp, file_get_contents($file));
      gzclose($fp);
      unlink($file);
  }
  ?&gt; 
  </code></pre>
  
  <p>The problem is, when I run the code I get the following error - </p>
  
  <pre><code>This page contains the following errors:
  
  error on line 44 at column 6: XML declaration allowed only at the start of the document
  Below is a rendering of the page up to the first error.
  </code></pre>
  
  <p>And only first 10 id's are selected and are not printed in xml format.Later when I look at .gz files, file1 contains 1-10 id's, file2 contains 1-20 id's which it was suppose to contain 11-20 id's.........file10 contains 1-100 records, it was suppose to contain 91-100 id's. </p>
  
  <p>Also when I comment out the line <code>Header('Content-type: text/xml')</code> I get all the id's printed in an unformatted way, in a single line.
  Can someone please help me overcome these 2 bugs?</p>