I've been following a tutorial to create an XML Page using PHP. Below is the code.
<?
header('Content-type: text/xml');
mysql_connect('localhost','root','admin');
mysql_select_db('test');
$sql = "Select * from `books`";
$q = mysql_query($sql) or die(mysql_error());
$dom = new DOMDocument();
$datas = $dom->createElement('datas');
$dom->appendChild($datas);
while($r = mysql_fetch_array($q)){
$id = $dom->createElement('id');
$idText = $dom->createTextNode($r['id']);
$id->appendChild($idText);
$title = $dom->createElement('title');
$titleText = $dom->createTextNode($r['title']);
$title->appendChild($titleText);
$author = $dom->createElement('author');
$authorText = $dom->createTextNode($r['author']);
$author->appendChild($authorText);
$book = $dom->createElement('book');
$book->appendChild($id);
$book->appendChild($title);
$book->appendChild($author);
$datas->appendChild($book);
}
$xmlString = $dom->saveXML();
echo $xmlString;
?>
But for some reason when I run this I get an error which is - "error on line 5 at column 1: Extra content at the end of the document"