Hi All, I am getting the error in php (postgres connection string) as mentioned below :
XML Parsing Error: not well-formed
Location: http://localhost:xyz.php
Line Number 1, Column 5: … i.e.
Here is my code :
1 <?php
2 // Database connection settings
3 define(“PG_DB” , “testgis”);
4 define(“PG_HOST”, “localhost”);
5 define(“PG_USER”, “postgres”);
6 define(“PG_PORT”, “5432”);
7 define(“TABLE”, “roads”);
8 define(“PWD”, “root”);
9 $counter = $pathlength = 0;
10
11 // Retrieve start point
// $start = split(’ ',$_REQUEST[‘startpoint’]);
$startPoint = array(-6.466140625, 1.13427734375);
// Retrieve end point
// $end = split(' ',$_REQUEST['finalpoint']);
$endPoint = array(21.5389765625, 18.993828125);
// Find the nearest edge
$startEdge = findNearestEdge($startPoint);
$endEdge = findNearestEdge($endPoint);
// FUNCTION findNearestEdge
function findNearestEdge($lonlat) {
// Connect to database
$dbcon = pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER." password=".PWD);
$sql = "SELECT gid, source, target, the_geom,
distance(the_geom, GeometryFromText(
'POINT(".$lonlat[0]." ".$lonlat[1].")', -1)) AS dist
FROM ".TABLE."
WHERE the_geom && setsrid(
'BOX3D(".($lonlat[0]-200)."
".($lonlat[1]-200).",
".($lonlat[0]+200)."
".($lonlat[1]+200).")'::box3d, -1)
ORDER BY dist LIMIT 1";
$query = pg_query($dbcon,$sql);
$edge['gid'] = pg_fetch_result($query, 0, 0);
$edge['source'] = pg_fetch_result($query, 0, 1);
$edge['target'] = pg_fetch_result($query, 0, 2);
$edge['the_geom'] = pg_fetch_result($query, 0, 3);
echo "edge=" . $edge['gid'] . "</br>";
echo "source=" . $edge['source'] . "</br>";
echo "target=" . $edge['target'] . "</br>";
echo "the_geom=" . $edge['the_geom'] . "</br>";
// Close database connection
pg_close($dbcon);
return $edge;
}
echo "startedge=" . $startEdge['source'] . "</br>";
echo "endedge=" . $endEdge['target'] . "</br>";
// Select the routing algorithm
$sql = "SELECT rt.gid, AsText(rt.the_geom) AS wkt,
length(rt.the_geom) AS length, ".TABLE.".id
FROM ".TABLE.",
(SELECT gid, the_geom
FROM dijkstra_sp_delta(
'".TABLE."',
".$startEdge['source'].",
".$endEdge['target'].",
3000)
) as rt
WHERE ".TABLE.".gid=rt.gid;";
// close switch
// Database connection and query
$dbcon = pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER." password=".PWD);
$query = pg_query($dbcon,$sql);
// Return route as XML
$xml = '<?xml version="1.0" entity_encoding="UTF-8" standalone="yes" ?>'."\
";
$xml .= "<route>
";
// Add edges to XML file
while($edge=pg_fetch_assoc($query)) {
$pathlength += $edge['length'];
$xml .= "\ <edge id='".++$counter."'>\
“;
$xml .= “\ \ <id>”.$edge[‘id’].”</id>
“;
$xml .= “\ \ <wkt>”.$edge[‘wkt’].”</wkt>
“;
$xml .= “\ \ <length>”.round(($pathlength/1000),3).”</length>
";
$xml .= "\ </edge>
";
}
$xml .= "</route>\
";
// Close database connection
pg_close($dbcon);
// Return routing result
header('Content-type: text/xml',true);
echo $xml;
?>
Here is my output:
edge=43</br>source=37</br>target=32</br>the_geom=0105000000010000000102000000060000004C60BAF79BFE26C0AB758262C883B0BF94154C4DC8F324C032899FD65E16CD3FC145A98EFDEF21C0471698AEA01ADE3FD0E9F797CF741DC0253C44196163E83F4A50F132FC9718C094369EEDB8DCF03FD4390ADA895014C0574EDC4003280240</br>edge=28</br>source=22</br>target=25</br>the_geom=0105000000010000000102000000030000000000000000002F400000000000002F400000000000003340000000000000334000000000008037400000000000003340</br>startedge=37</br>endedge=25</br><?xml version=“1.0” entity_encoding=“UTF-8” standalone=“yes” ?>
<route>
<edge id=‘1’>
<id>43</id>
<wkt>MULTILINESTRING((-11.497283689023 -0.064510845232198,-10.4761375575425 0.227245192333677,-8.9687313634521 0.470375223638574,-7.36407315683978 0.762131261204449,-6.1484230003153 1.05388729877032,-5.07865086257376 2.26953745529481))</wkt>
<length>0.007</length>
</edge>
<edge id=‘2’>
<id>38</id>
<wkt>MULTILINESTRING((-4 4,-4.46274864568763 3.93807848556878,-4.75377039792406 3.78754999303269,-4.90429889046015 3.59688056915365,-4.9946159859818 3.4563873094533,-5.10500354717493 3.15533032438113,-5.14514447851788 2.8643085721447,-5.15517971135362 2.53314588856532,-5.07865086257376 2.26953745529481))</wkt>
<length>0.01</length>
</edge>
Pl help me to resolve this is problem.
Thanks in advance.