GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Extracting XML in PHP  XML
Forum Index -> FAQ - frequently asked questions
Author Message
smith7800



Joined: 01/09/2008 01:57:56
Messages: 3
Offline

I'm trying to certain data from the call to geoname using php.
This is what I'm trying to do:

$url="http://ws.geonames.org/countrySubdivision?lat=47.03&lng=10.2&style=full";
$output = file_get_contents($url);
$xml = simplexml_load_string($output);
echo $xml->countryName."<br />";
echo $xml->adminName1."<br />";

This has worked for other reverse lookup services, buy I can't get it to work here. Can anybody help?
geotree


[Avatar]
Joined: 23/07/2007 18:28:40
Messages: 138
Location: France
Offline

countrySubdivision level is missing in your output object.

Try this :

Code:
 $url="http://ws.geonames.org/countrySubdivision?lat=47.03&lng=10.2&style=full";
 $output = file_get_contents($url);
 $xml = simplexml_load_string($output);
 echo "<pre>";print_r($xml);echo "</pre>";
 echo $xml->countrySubdivision->countryName."<br />";
 echo $xml->countrySubdivision->adminName1."<br />";
 

Christophe
geotree.geonames.org
geotree.geonames.org/geotree.html
[WWW]
smith7800



Joined: 01/09/2008 01:57:56
Messages: 3
Offline

Hey, thanks a lot. That worked perfectly.
nikey



Joined: 13/10/2010 02:38:20
Messages: 4
Offline

 
Forum Index -> FAQ - frequently asked questions
Go to:   
Powered by JForum 2.1.5 © JForum Team