私は Javascript と PHP で XML ファイルを書きました...そして、それが言ったところでエラーが発生していますXML Parsing Error: not well-formed
。誰でも私を助けてください。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>
2 番目のファイルは次のとおりです。
<?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>';
?>