Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi All,

I am trying to get the value of a specific node in an XML file. My
code is below, I have added comments pointing out where I believe the
problem to be, specifically on this line:

$coordinates = $xml->Response->Placemark->Point->coordinates;

Which, for some reason is empty. I am running PHP4, is this possible
in 4? You will notice I have replaced one of the lines which only
worked with PHP5 (SimpleXMLElement).

Note that my code was based on this sample:

I later looked at this one from the Google maps API documentation

I can confirm that the XML is returned and valid.

Any help/suggestions much appreciated - I sat down 3hrs ago thinking
this would be a 30 min job! :o)

Thank you!


   // Your Google Maps API key
   $key = "<MYGOOGLEAPICODE>";

   // Desired address
   $address = "http://maps.google.co.uk/maps/geo?q =<SOME POST

   // Retrieve the URL contents
   $page = file_get_contents($address);

   // Parse the returned XML file
   // $xml = new SimpleXMLElement($page); <-- PHP 5 Required
   $xml = domxml_open_mem($page);

   // Parse the coordinate string
   $coordinates = $xml->Response->Placemark->Point->coordinates;
<---- This var is empty
   $coordinatesSplit = split(",", $coordinates);

   // Format: Longitude, Latitude, Altitude
   $lat = $coordinatesSplit[1];
   $lng = $coordinatesSplit[0];

   // Diags
   print "lat" . $lat;
   print "lng" . $lng;

   print $coordinates;  <---- Outputs nothing


Re: XML - PHP4?


Quoted text here. Click to load it

You didn't do any error checking for domxml_open_mem. Check to see if  
that's the source of the problem.

if ( !$dom = domxml_open_mem($str) ) {
    echo 'Error parsing';

Curtis, http://dyersweb.com

Re: XML - PHP4?

Quoted text here. Click to load it

Micha - Thank you, but PHP4 is capable of what I need to do, I will
consider PHP5 soon, but not right now.

Curtis - Thanks, I tried that and the XML does parse Ok, so the XML is

Any other ideas?

Site Timeline