Php google map API中的xml解析错误
我已经用Javascript和PHP编写了一个XML文件。。。我有一个错误,它说Php google map API中的xml解析错误,php,javascript,xml,Php,Javascript,Xml,我已经用Javascript和PHP编写了一个XML文件。。。我有一个错误,它说XML解析错误:格式不正确。谁能帮帮我吗。我正在上传2个文件 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps AJAX +
XML解析错误:格式不正确
。谁能帮帮我吗。我正在上传2个文件
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps AJAX + mySQL/PHP Example</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
var customIcons = {
criminal: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
offender: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(-20.1666591, 57.503457),
zoom: 13,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
downloadUrl("showsubject-script1.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var subid = markers[i].getAttribute("subid");
var subaddress = markers[i].getAttribute("subaddress");
var subremarks = markers[i].getAttribute("subremarks");
var subtype = markers[i].getAttribute("subtype");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("sublat")),
parseFloat(markers[i].getAttribute("sublng")));
var html = "<b>" + subid + "</b> <br/>" + subaddress + "</b> <br/>" + subremarks ;
var icon = customIcons[subtype] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
</head>
<body onLoad="load()">
<div id="map" style="width: 900px; height: 1000px"></div>
</body>
</html>
googlemapsajax+mySQL/PHP示例
var customIcons={
罪犯:{
图标:'http://labs.google.com/ridefinder/images/mm_20_blue.png',
影子:'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
罪犯:{
图标:'http://labs.google.com/ridefinder/images/mm_20_red.png',
影子:'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
函数加载(){
var map=new google.maps.map(document.getElementById(“map”){
中心:新google.maps.LatLng(-20.1666591,57.503457),
缩放:13,
mapTypeId:“路线图”
});
var infoWindow=new google.maps.infoWindow;
下载URL(“showsubject-script1.php”,函数(数据){
var xml=data.responseXML;
var markers=xml.documentElement.getElementsByTagName(“标记”);
对于(var i=0;i“+子地址+”
“+子备注;
var icon=customIcons[subtype]| |{};
var marker=new google.maps.marker({
地图:地图,
位置:点,,
icon:icon.icon,
});
bindInfoWindow(标记、地图、infoWindow、html);
}
});
}
函数bindInfoWindow(标记、地图、infoWindow、html){
google.maps.event.addListener(标记'click',函数(){
setContent(html);
信息窗口。打开(地图、标记);
});
}
函数下载url(url,回调){
var请求=window.ActiveXObject?
新的ActiveXObject('Microsoft.XMLHTTP'):
新的XMLHttpRequest;
request.onreadystatechange=函数(){
if(request.readyState==4){
request.onreadystatechange=doNothing;
回调(请求、请求、状态);
}
};
打开('GET',url,true);
请求发送(空);
}
函数doNothing(){}
第二个文件是:
<?php
require("db.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
$query = mysql_query ("SELECT id,addressfound,remarks, lat, lng,'criminal' FROM criminalrecord");
while ($row = mysql_fetch_array($query))
{
$insert = mysql_query("insert into subjectrecord (subid,subaddress,subremarks,sublat,sublng,subtype) values ('$row[0]','$row[1]','$row[2]','$row[3]','$row[4]','$row[5]') ");
}
$query1 = mysql_query ("SELECT id,addressfound,remarks, lat, lng,'offender' subject FROM offenderrecord");
while ($row1 = mysql_fetch_array($query1))
{
$insert1 = mysql_query("insert into subjectrecord (subid,subaddress,subremarks,sublat,sublng,subtype) values ('$row1[0]','$row1[1]','$row1[2]','$row1[3]','$row1[4]','$row1[5]') ");
}
$query2 = mysql_query ("SELECT subid,subaddress,subremarks,sublat,sublng,subtype FROM subjectrecord");
header("Content-type: text/xml");
echo '</markers>';
while ($row2 = @mysql_fetch_assoc($query2)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'subid="' . parseToXML($row2['subid']) . '" ';
echo 'subaddress="' . parseToXML($row2['subaddress']) . '" ';
echo 'subremarks="' . parseToXML($row2['subremarks']) . '" ';
echo 'sublat="' . $row2['sublat'] . '" ';
echo 'sublng="' . $row2['sublng'] . '" ';
echo 'subtype="' . $row2['subtype'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
正如@CBroe所建议的,您的XML输出格式不正确。问题似乎是第一个
,它应该是一个开始标记,即
获取XML输出,并通过一个在线可用的XML验证工具进行验证。没有用于验证的DTD。。这是关于谷歌地图的,你不必对照DTD检查它,只是为了获得良好的信息…嘿,太好了,现在它可以工作了,我刚刚犯了这个错误。。应该是。。thnxx lotsssssure。。有15个名声是很有道理的