klous-1 Posted July 26, 2011 Share Posted July 26, 2011 Hi everyone, I'm simply trying to grab a simple element from an XML. The XML has the following format: <geonames> <geoname> <toponymName>Grand Tikal Futura Hotel</toponymName> <name>Grand Tikal Futura Hotel</name> <lat>14.618</lat> <lng>-90.5249</lng> <geonameId>6475052</geonameId> <countryCode>GT</countryCode> <countryName>Guatemala</countryName> <fcl>S</fcl> <fcode>HTL</fcode> <distance>1.23124</distance> </geoname> </geonames> My PHP is currently like this (note the link to the XML is calling two PHP variables as part of it's URL) <?PHP header('Content-Type: text/plain'); $userId = '-495015601289433027'; if ( $_GET['user'] ) { if ( is_numeric( $_GET['user'] ) ) $userId = $_GET['user']; else exit('This isn\'t a valid user id.'); } $url = 'http://www.google.com/latitude/apps/badge/api?user='.$userId.'&type=json'; // We get the content $content = file_get_contents( $url ); // We convert the JSON to an object $json = json_decode( $content ); $coord = $json->features[0]->geometry->coordinates; $timeStamp = $json->features[0]->properties->timeStamp; if ( ! $coord ) exit('This user doesn\'t exist.'); $date = date( 'Y-m-d H:i', $timeStamp ); $lat = $coord[1]; $lon = $coord[0]; $sXML = new SimpleXMLElement('http://api.geonames.org/findNearby?lat=$lat&lng=$lon&username=klous&style=short', NULL, TRUE); print_r ($sXML); ?> But with this I get an error: [message] => error parsing parameter [value] => 14 I've been trying and searching all morning, lots of different ideas, but with no luck. At the moment, for simplicity, I'm simply trying to output the needed field "GeonameId". I would really appreciate some help, and apologies.... I am, quite obviously, a novice! Thanks! Link to comment https://forums.phpfreaks.com/topic/242894-retrieving-xml-data-from-dynamic-xml-file/ Share on other sites More sharing options...
btherl Posted July 27, 2011 Share Posted July 27, 2011 I think you need to refer to the documentation for the geonames API. If you link to the docs I may be able to help you. Link to comment https://forums.phpfreaks.com/topic/242894-retrieving-xml-data-from-dynamic-xml-file/#findComment-1247632 Share on other sites More sharing options...
klous-1 Posted July 27, 2011 Author Share Posted July 27, 2011 So I got the script working..... <?PHP header('Content-Type: text/plain'); $userId = '-USERNOHERE######'; if ( $_GET['user'] ) { if ( is_numeric( $_GET['user'] ) ) $userId = $_GET['user']; else exit('This isn\'t a valid user id.'); } $url = 'http://www.google.com/latitude/apps/badge/api?user='.$userId.'&type=json'; // We get the content $content = file_get_contents( $url ); // We convert the JSON to an object $json = json_decode( $content ); $coord = $json->features[0]->geometry->coordinates; $timeStamp = $json->features[0]->properties->timeStamp; if ( ! $coord ) exit('This user doesn\'t exist.'); $date = date( 'Y-m-d H:i', $timeStamp ); $lat = $coord[1]; $lon = $coord[0]; echo '<param name="flashvars" value="location_id=gn:'; $sXML = new SimpleXMLElement('http://api.geonames.org/findNearby?lat='.$lat.'&lng='.$lon.'&username=klous&style=short', NULL, TRUE); foreach($sXML as $geo) // loop through our records { echo $geo->geonameId; } echo'&landscape=airport&time_format=12&us=uk&background=#666666&mini_momentBar=false©right_bar=false"><a href="http://yowindow.com/weatherwidget.php" style="width: 180px; height: 140px; display: block; text-indent: -50000px; font-size: 0px; background: #DDF url("http://yowindow.com/img/logo") no-repeat scroll 50% 50%">'; echo $lat.$lon; ?> Only to find that actually, the geonameId isn't available on the "Findnearbyweather" so essentially, this is useless. :'( What I'd wanted to do, was using google Latitude to update my location, also update the location on my little weather widget....alas.... Link to comment https://forums.phpfreaks.com/topic/242894-retrieving-xml-data-from-dynamic-xml-file/#findComment-1247638 Share on other sites More sharing options...
klous-1 Posted July 27, 2011 Author Share Posted July 27, 2011 I think you need to refer to the documentation for the geonames API. If you link to the docs I may be able to help you. Thanks for the reply, btherl....but, as you can see in my post above, all apparently, is lost..... Link to comment https://forums.phpfreaks.com/topic/242894-retrieving-xml-data-from-dynamic-xml-file/#findComment-1247639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.