Click to See Complete Forum and Search --> : Extra Content error when creating xml in PHP


aresyama
June 1st, 2011, 12:12 PM
I keep getting this error:

error on line 3 at column 1: Extra content at the end of the document

When running this script:

<?php

require_once('../Connections/RadarDance.php');

// Start XML file, create parent node

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);


// Set the active MySQL database

$db_selected = mysql_select_db($database_RadarDance, $RadarDance);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table

$query = "SELECT * FROM swingdancelist1 WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("VenueName",$row['VenueName']);
$newnode->setAttribute("Address", $row['Address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
}
echo $dom->saveXML();

?>

Every site seems to say it's b/c i'm not specifying a root, but apparently i can't figure out how to do that (i've tried every way i can think/find). Help please!