I work on a Windows 2003 Server with PHP 5.
This works well:
$url = "http://maps.google.com/maps/geo?q=60488%20,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";
If you copy the string an put it in your browser you will get excelent xml.
...but if I trye to get better results with Google Maps - I add my Street an Number - I get with Browser XML, but no Results with MagicParser.
__________________________________
Here is my request URL:
$url =
"http://maps.google.com/maps/geo?q=60488%20Langweidenstra%C3%9Fe%2056,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";
If you put it into the Demo-URL field on this site - no result will appear.
If you copy the xml from browser and put it into the Demo-String field on this site the parser works well.
___________________
___________________
___________________
Now I tryed to make my own programm. First I tryed with url:
$format_string = "xml|kml/Response/Placemark/";
MagicParser_parse($url,"myRecordHandler",$format_string);
___________________
Than I tryed to parse a string:
$string = http_get($url);
preg_match('/(<\?xml version.*?<\/kml>)/', $string, $kml);
$format_string = "xml|kml/Response/Placemark/";
MagicParser_parse($kml[1],"myRecordHandler",$format_string);
___________________
At last I tryed to parse a file
$string = http_get($url);
preg_match('/(<\?xml version.*?<\/kml>)/', $string, $kml);
$file = 'tmp/kml.xml';
$fh = fopen($file, 'w');
fwrite($fh, $kml[1]);
fclose ( $fh);
$format_string = "xml|kml/Response/Placemark/";
MagicParser_parse($file,"myRecordHandler",$format_string);
...now I don't know how to solve the problem...
Do you know...?
Thanks!!
Hi,
This is down to an error in the character encoding of the response XML document in the second URL where the address is used. The XML contains data in the ISO-8859-1 character set, whereas the document is declared as UTF-8.
This causes the parser to abort because it cannot interpret the file correctly if the byte stream does not conform to the declared character set; so this is actually a problem with the original XML, not Magic Parser.
The work around is to read the XML into a string, and then convert it to UTF-8 using the utf8_encode() function. You can then pass the data to MagicParser_parse() using the string:// prefix to get Magic Parser to parse the data directly from memory.
Here's an example code using both of your example Google Maps API URLs:
<?php
header("Content-Type: text/plain;charset=UTF-8");
require("MagicParser.php");
function myRecordHandler($record)
{
print_r($record);
}
$url1 = "http://maps.google.com/maps/geo?q=60488%20,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";
$url2 = "http://maps.google.com/maps/geo?q=60488%20Langweidenstra%C3%9Fe%2056,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";
$fp = fopen($url2,"r");
$data = "";
while(!feof($fp))
{
$data .= fread($fp,1024);
}
fclose($fp);
$data = utf8_encode($data);
MagicParser_parse("string://".$data,"myRecordHandler","xml|KML/");
?>
Hope this helps,
Cheers,
David.
Thank you sooo muche!! It works very well.
Hans-Martin Aurich
Internetservice
www.WebConsultant.de
Hi,
Sorry about the problem you are having.
I have been able to recreate the problem, so now I am trying to work out what is going on. I will able to look at this soon and get back to you as soon as possible...
Apologies for the inconvenience;
Cheers,
David.