Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Retrieve values for a complicate XML file


  • Please log in to reply
1 reply to this topic

#1 toto_7


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 16 February 2012 - 04:56 PM


I didn't use XML files for a very long time and I have forgot how to interact with complicate files. Need to retrieve the value of an Element in an XML file that is sitting too deep in that. For example:

I want to retrieve the latitude value that appears here: DirectionsResponse/route/leg/step/start_location/lat. Need to do the same for Longitude and latitude/Longitude for the end_location. "leg" contains more elements but I want just "step". Also, "step" elements are not always the same quantity, so need to check the size of the "leg" or how many "step" contains. I made some tries but all have failed! Please anybody knows how my for loop should be in order to getting correctly all "start_location" and "end_location" from all "step"?

Thanks in advance,
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2 BlackRabbit


    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 11 April 2012 - 05:12 AM

Here you have some good old sample code :

txt=txt+"<title>The life of the javascript coder</title>";
txt=txt+"<author>Giada De Laurentiis</author>";

if (window.DOMParser)
  parser=new DOMParser();
else // Internet Explorer
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

it works with the xmlDoc object in windows, understanding you are working in ASP.NET / ajax

you can always parse it with RegExp :
here is a reference :

  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download