I'm getting an "Extra content at the end of the document" error here. I believe it has something to do with there being more than one document root. How may I fix this please? Thanks.
<?php
$key = $_GET['key'];
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parent = $dom->appendChild($node);
//$dom->formatOutput = true;
// Opens a connection to a MySQL server
$connection=mysql_connect ('localhost', 'wordpressdbadmin', 'wordpressdbpass');
if (!$connection)
{
die('Not connected : ' . mysql_error());
}
else
{
$db_selected = mysql_select_db(geocodeindex3, $connection);
$query = "SELECT locations.name, locations.add, locations.lat, locations.long FROM locations where id=".$key.";";
$result = mysql_query($query);
header("Content-type: text/xml");
while ($row = mysql_fetch_array($result))
{
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parent->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['add']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['long']);
}
echo $dom->saveXML();
}
?>
No comments:
Post a Comment