Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Retrieve values for a complicate XML file (Java)

 
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
IBM DB2 Eclipse IDE VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use XPath.

http://www.w3schools.com/xpath/

XPath is very easy to learn and part of the JRE since Version 5.

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's cool thanks for quick reply. There is a problem however. Cause I'm working on Android API 7 and need to stick on that API, I can't use XPath stuff. There is any way to make it work on API 7 or there is an alternative way using SAX Parser?

Thanks in advance,
toto_7
 
Marshal
Posts: 28288
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're limited to using only SAX, then you won't be writing any loops anyway. Let's see what code you have so far and maybe you could ask a question about that code.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Jaxen library implements XPath and works fine on Android 1.x. It's what I use to process geo XML on Android.
 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I believe is better to stick to current way, because I don't want to mess with new libs. So for example I have a file like this .. link. As you can see contains a lot of <step>. So I want to retrieve from each <step> the <start_location>/<lat>,<lng> and <end_location>/<lat>,<lng>. How I will be able to do that on API 7? For each route the <step> element vary...

Thanks in advance,
toto_7
 
Paul Clapham
Marshal
Posts: 28288
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me move this to the Android forum, then, if it's a question about Android programming.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with adding the library? It's not like it's big.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic