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.
<?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 = '<?xml version="1.0"?>';
$_xml .="<winerys>";
while($row = mysqli_fetch_array($result)) {
$_xml .="<winery>";
$_xml .="<winery_id>".$row['winery_id']."</winery_id>";
$_xml .="<winery_name>".$row['winery_name']."</winery_name>";
$_xml .="<region_id>".$row['region_id']."</region_id>";
$_xml .="</winery>";
}
$_xml .="</winerys>";
//Parse and create an xml object using the string
$xmlobj=new SimpleXMLElement($_xml);
//And output
print $xmlobj->asXML();
//or we could write to a file
$xmlobj->asXML(winerys.xml);
?>