Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Parsing XML

Google Geocode API

2:02 am on Jun 11, 2013 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
votes: 1

I don't know if it is because I have a shaky foundation parsing XML or because the Google Geocode API was written by somebody drunk, but I am having a difficult time parsing their XML file and was hoping for some help. I'd like to think it was more of my shaky foundation rather than the drunk coder, but the XML seems strangely nested and because of this I'm having a hard time using online tutorials for parsing XML.

A sample XML file I'm working with:

var url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=47.616483,-122.319164&sensor=false";

My script so far:

var xml = new XMLHttpRequest();
xml.open("GET", url, false);

If available, I'm trying to get the first Long Name for "neighborhood", "sublocality", "locality", and the first Short Name for "country".

I am not using jQuery and do not want to load a huge library for what I hope will be a simple task. If it makes a difference a JSON format is also available by changing xml to json.
5:35 pm on June 11, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
votes: 0

If using XML, you need to access the data using DOM functions.
I would recommend using JSON instead, as it converts to a JavaScript object.

As for not loading jQuery -- that's fine. But your current AJAX component is insufficient.
I would start here [w3schools.com], going through the next several pages. That way your own AJAX component can be put into its own file for easy reference in multiple projects.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members