我写了一个php代码来生成包含mysql表中标记的xml文件。但是我收到了这个错误信息:
XML解析错误:XML或文本声明不在实体的开头 地点:http://localhost/onlinetaxi/phpsqlsearch_genxml.php 第5行,第1列: ^
我在谷歌搜索它,答案说它是由白色空间引起的,我应该删除它。它删除了每个空白区域,但问题仍然存在 有人可以帮助我吗?
<html>
<head>
</head>
<body>
<?php
require("phpsqlsearch_dbinfo.php");
// Get parameters from URL
//$center_lat = $_GET["lat"];
//$center_lng = $_GET["lng"];
//$radius = $_GET["radius"];
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a mySQL server
$connection=mysql_connect ("localhost","root");
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}
// Search the rows in the markers table
$query = "SELECT agencyaddress, agencyname, lat, lng FROM agency ";
// mysql_real_escape_string($center_lat),
// mysql_real_escape_string($center_lng),
// mysql_real_escape_string($center_lat),
// mysql_real_escape_string($radius));
$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)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['agencyname']);
$newnode->setAttribute("address", $row['agencyaddress']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
}
echo $dom->saveXML();
?>
</body>
</html>