homepage Welcome to WebmasterWorld Guest from 54.234.228.64
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Parsing XML
Google Geocode API
ocon




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

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);
xml.send(null);
if(xml.status==200){
...
alert(neighborhood);
}

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.

 

DrDoc




msg:4583206
 5:35 pm on Jun 11, 2013 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved