Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Retrieve values for a complicate XML file

xml

  • Please log in to reply
1 reply to this topic

#1 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 16 February 2012 - 04:56 PM

Hello,

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,
toto_7
  • 0

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

-Michael Sinz

#2 BlackRabbit

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="<bookstore><book>";
txt=txt+"<title>The life of the javascript coder</title>";
txt=txt+"<author>Giada De Laurentiis</author>";
txt=txt+"<year>2008</year>";
txt=txt+"</book></bookstore>";

if (window.DOMParser)
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(txt,"text/xml");
  }
else // Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.loadXML(txt);
  }

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 :

http://www.regular-e...iptexample.html
  • 0





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