Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:51:00+00:00 2026-06-12T23:51:00+00:00

I am parsing the XML returned from Google Map API V3. Here is the

  • 0

I am parsing the XML returned from Google Map API V3. Here is the typical XML returned:

<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
  <name>40.74445606,-73.97495072</name>
  <Status>
    <code>200</code>
    <request>geocode</request>
  </Status>
  <Placemark id="p1">
    <address>317 E 34th St, New York, NY 10016, USA</address>
    <AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><Locality><LocalityName>New York</LocalityName><Thoroughfare><ThoroughfareName>317 E 34th St</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>10016</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="40.7458050" south="40.7431070" east="-73.9736017" west="-73.9762997" />
    </ExtendedData>
    <Point><coordinates>-73.9749507,40.7444560,0</coordinates></Point>
  </Placemark>
</Response></kml>

Here is a fragment of the PHP code I’m using to parse it:

$xml = new SimpleXMLElement($url, null, true);
$xml->registerXPathNamespace('http', 'http://earth.google.com/kml/2.0');
$LatLonBox_result = $xml->xpath('//http:LatLonBox');

echo "North: " . $LatLonBox_result[0]["north"] . "\n";
echo "South: " . $LatLonBox_result[0]["south"] . "\n";
echo "East: " . $LatLonBox_result[0]["east"] . "\n";
echo "West: " . $LatLonBox_result[0]["west"] . "\n";

var_dump($LatLonBox_result);

Here is the edited output:

North: 40.7458050
South: 40.7431070
East: -73.9736017
West: -73.9762997
array(1) {
  [0]=>
  object(SimpleXMLElement)#10 (1) {
    ["@attributes"]=>
    array(4) {
      ["north"]=>
      string(10) "40.7458050"
      ["south"]=>
      string(10) "40.7431070"
      ["east"]=>
      string(11) "-73.9736017"
      ["west"]=>
      string(11) "-73.9762997"
    }
  }
}

Using $LatLonBox_result[0][“north”] seems ugly looking to me. Is this just how things are when working with xpath? I was expecting a returned value perhaps something like $LatLonBox_result[“north”] and not have the first dimension of the array. Or is this approach wrong?
If there is a better way to do this, please kindly enlighten me. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:51:01+00:00Added an answer on June 12, 2026 at 11:51 pm

    SimpleXMLElement::xpath returns always an array (in fact you are getting the first element of it) with the results found (regardless they are only one or more), or FALSE in case of error.

    I think your code is just fine, except for being not very robust. You better check the result with empty($result) before doing anything else with it.

    $LatLonBox_result = $xml->xpath('//http:LatLonBox');
    
    if (!empty($LatLonBox_result)) {
        echo "North: " . $LatLonBox_result[0]["north"] . "\n";
        echo "South: " . $LatLonBox_result[0]["south"] . "\n";
        echo "East: " . $LatLonBox_result[0]["east"] . "\n";
        echo "West: " . $LatLonBox_result[0]["west"] . "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am parsing XML returned from a website but sadly it is slightly malformed.
I am parsing XML that gets returned from a web service. If it is
I am having trouble parsing some returned XML using this command: XML::Parser.string(xml_string).parse Here is
Im trying to parse the XML returned by the Google Geo code API ,but
I am having a little trouble with parsing XML from a google checkout response.
I am parsing xml file from server using xmlParser in Android. When i print
I'm parsing XML to get multiple markers directly from the database, so used the
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
Okay. Here's the code. XML Parsing Error: not well-formed <item_to_page_title><![CDATA[Breaking news, real-time scores and
i have a multidimensional array. the array is returned by parsing xml using curl.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.