ajax - Javascript - best way to parse custom tags -


this question has answer here:

i wrote api returns following

 <location><lat>41.47033705</lat><lon>-81.93612862</lon></location>  <location><lat>41.470320224762</lat><lon>-81.9364535808563</lon></location>  <location><lat>41.4704650640488</lat><lon>-81.9449239969254</lon></location>  <location><lat>41.4780235290527</lat><lon>-81.8454140424728</lon></location>  <location><lat>41.48597253</lat><lon>-81.82579113</lon></location> 

i have ajax call gets , need use in javascript.

ultimately , 2d array [lat,lon]

what least amount of code this?

assuming response valid xml, can use getelementsbytagname , push array:

var arr = []; (var location in response.getelementsbytagname('location')) {     arr.push([         parsefloat(location.getelementsbytagname('lat')[0]),          parsefloat(location.getelementsbytagname('lon')[0])     ]); } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -