I am trying to export data from MySQL table to XML file.
I am using Adobe Dreamweaver CC 2015 to create index.php file contains the below code:
<?php
header('Content-type: text/xml');
$xmlout = "<?xml version=\"1.0\" ?>";
$xmlout .= "<list>";
$db = new PDO('mysql:host=hostname;dbname=dbname','dbusername','password');
$stmt = $db->prepare("select * from tablename");
$stmt->execute();
while($row = $stmt->fetch()){
$xmlout .= "\t<persons>\n";
$xmlout .= "\t\t<id>".$row['ID']."</id>\n";
$xmlout .= "\t\t<name>".$row['name']."</name >\n";
$xmlout .= "\t\t<phone>".$row['phone']."</phone >\n";
$xmlout .= "\t\t<address>".$row['address']."</address >\n";
$xmlout .= "\t\t<status>".$row['status']."</status>\n";
$xmlout .= "\t</persons>\n";
}
$xmlout .= "</list>";
echo $xmlout;
?>
when I run the page I find this error:
error on line 10 at column 8: Extra content at the end of the document
the result in chrome Inspect > Sources > index.php
<?xml version="1.0" ?>
<list>
<persons>
<id>1</id>
<name>John</name>
<phone>123456</phone>
<address>123 street</address>
<status>Ready</status>
</persons>
</list>
but there is a . after and when I tried to use http://www.xmlvalidation.com/ to validate my XML output I found that
</list>
what should I do to fix this error?