【发布时间】:2013-03-23 16:09:39
【问题描述】:
大家好,我正在尝试显示一个谷歌地图,其中包含从我关注的数据库中检索到的动态位置 developers.google.com/maps/articles on phpsqlajax_v3。我创建了数据库,表格看起来像这样
trnsportpublic 表
transportpublicid int 11 自动增量
transportType varchar 60
costPerKm 十进制(7,2)
地址 varchar 800
teleNo int 10
webLink varchar 300
描述 varchar 800
纬度双(10,6)
lng double(10,6)
GenerateXml.php
<?php
require("db_connection.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr); // line 11
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Select all the rows in the markers table
$query = "SELECT transportType,costPerKm,address,teleNo,webLink,lat,lng FROM transportpublic";
$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<transportpublic>';
// Iterate through the rows, printing XML nodes for each
while ($row = mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'transportType="' . parseToXML($row['transportType']) . '" ';
echo 'costPerKm="' . $row['costPerKm'] . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'teleNo="' . $row['teleNo'] . '" ';
echo 'webLink="' . parseToXML($row['webLink']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo '/>';
}
// End XML file
echo '</transportpublic>';
?>
当我在浏览器上运行 GenerateXml.php 时,我会感到兴奋
XML Parsing Error: junk after document element
Location: http://localhost:8080/testserver/generateXml.php
Line Number 11, Column 8:
</html>
<transportpublic>
<marker transportType="Bus" costPerKm="1.50" address="abc" teleNo="112554476" webLink="http://www.abc.html" lat="0.000000" lng="0.000000" />
<marker transportType="Train" costPerKm="12.00" address="abc" teleNo="118745963" webLink="http://www.abc.html" lat="0.000000" lng="0.000000" />
<marker transportType="hmmmm" costPerKm="40.00" address="abc" teleNo="112541254" webLink="http://www.abc.html" lat="-33.005985" lng="-58.501824" />
<marker transportType="test" costPerKm="2.00" address="abc" teleNo="112541258" webLink="http://www.abc.html" lat="39.785999" lng="-75.041976" />
<marker transportType="test2" costPerKm="2.00" address="abc" teleNo="112541254" webLink="http://www.abc.html" lat="6.901698" lng="79.853854" />
</transportpublic>
-------^
我只知道在根元素之后我不应该解析任何数据,它将被视为垃圾,但在我的 GenerateXml.php 中,我在此行之后不做任何事情
echo '</transportpublic>';
请帮帮我。
【问题讨论】:
-
你真的应该使用 PHP 的 DOM 函数来创建你的 XML。
-
我很确定
</html>不属于这里。 -
@ÁlvaroG.Vicario 谢谢你先生你指出我正确的方向我仔细检查了.php文件但错过了“db_connection.php”它有 在其中,我删除了 html 标签,现在它可以工作了 :) 先生,为什么不把它作为答案.. 感谢大家的时间和精力,感谢。
标签: php google-maps-api-3 xml-parsing