title: Error on line 2 at column 1: Document is empty on php
body: <p>I got this:</p>
  
  <blockquote>
    <p>"error This page contains the following errors:</p>
    
    <p>error on line 2 at column 1: Document is empty Below is a rendering of
    the page up to the first error."</p>
  </blockquote>
  
  <p>When I run in google chrome this code:
      
  
  <pre><code>// Check connection
  if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
  }
  echo "Connected successfully\n";
  
  $xml = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;";
  $root_element = "catalog";
  $xml   .="\n"."&lt;".$root_element."&gt;"."\n"; 
  $sql="select * from `book`;";
  $result=mysqli_query($conn,$sql); 
  $row_cnt=$result-&gt;num_rows;
  if (!$result){
      die('Invalid query:'.mysql_error());
  }
   if ($row_cnt&gt;0){
      while($result_array =mysqli_fetch_assoc($result))
      {    $xml .="\t&lt;".$database.""; //&lt;book
  
          foreach($result_array as $key =&gt; $value)
          {
  
              $xml .="\t\t&lt;$key&gt;"; //&lt;id&gt;
              $xml .="$value";      //value
              $xml .="&lt;/$key&gt;\n";    //&lt;/id&gt;
  
  
          }
          $xml .="\t&lt;/".$database."&gt;\n";
      }
  }
  $xml .="\n&lt;/$root_element&gt;";
  header("Content-Type:text/xml");
  echo $xml;
  
  ?&gt;
  </code></pre>
  
  <p>and how I can show it like this?</p>
  
  <pre><code>&lt;catalog&gt;
     &lt;book id="bk101"&gt;
        &lt;author&gt;Gambardella, Matthew&lt;/author&gt;
        &lt;title&gt;XML Developer's Guide&lt;/title&gt;
        &lt;genre&gt;Computer&lt;/genre&gt;
        &lt;price&gt;44.95&lt;/price&gt;
        &lt;publish_date&gt;2000-10-01&lt;/publish_date&gt;
        &lt;description&gt;An in-depth look at creating applications 
        with XML.&lt;/description&gt;
     &lt;/book&gt;
  </code></pre>