title: xml error on line 2 at column 1: Document is empty
body: <p>I am trying to get data from my database and store it in an xml file and everytime I run the code i get this error on line 2 at column 1: Document is empty.</p>
  
  <pre><code> &lt;?php 
      header ("Content-Type:text/xml");//Tell browser to expect xml
      include ("db_connect.php");
      $query = "SELECT * FROM winery"; 
      $result = mysqli_query($connection, $query) or die ("Error in query: $query. ".mysql_error()); 
      //Top of xml file
      $_xml = '&lt;?xml version="1.0"?&gt;'; 
      $_xml .="&lt;winerys&gt;"; 
      while($row = mysqli_fetch_array($result)) { 
      $_xml .="&lt;winery&gt;"; 
      $_xml .="&lt;winery_id&gt;".$row['winery_id']."&lt;/winery_id&gt;"; 
      $_xml .="&lt;winery_name&gt;".$row['winery_name']."&lt;/winery_name&gt;"; 
      $_xml .="&lt;region_id&gt;".$row['region_id']."&lt;/region_id&gt;"; 
      $_xml .="&lt;/winery&gt;"; 
      } 
      $_xml .="&lt;/winerys&gt;"; 
      //Parse and create an xml object using the string
      $xmlobj=new SimpleXMLElement($_xml);
      //And output
      print $xmlobj-&gt;asXML();
      //or we could write to a file
      $xmlobj-&gt;asXML(winerys.xml);
      ?&gt;
  </code></pre>