• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

parsing xml

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using javax.xml.parsers to parse xml. may i know how do i get the attribute value of LatLonBox ?

from : <LatLonBox north="69.0600235" south="55.1365705" east="24.1773101" west="10.5922629"/>

ie. i want to get 69.0600235 and 24.1773101. thanks!

source:http://maps.google.com/maps/geo?q=spain&output=xml&oe=utf8&sensor=false&key=ABQIAAAA79oUcIWcib1M9h1BstM7bRQhL6vn9PNcXa7eSPja3EjRwozD8hR34PPElKF2YJPqtByPpv9nhfxDkw
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you using the classes in that package to parse XML? If you're using SAX, then you can access those values through the "Attributes atts" parameter of the startElement callback.
 
bryan lim
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public String getXMLValue(Document doc, String name) {
NodeList nlist=doc.getElementsByTagName(name);
String value = nlist.item(0).getFirstChild().getNodeValue();
return value;
}


i access using this method. However, i am not sure how to do it for multiple attributes.... can you give me some advise and show me example?

i want to get 69.0600235 and 24.1773101 from <LatLonBox north="69.0600235" south="55.1365705" east="24.1773101" west="10.5922629"/>



 
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
OK, so you're using DOM, not SAX. The code you showed doesn't handle attributes. Something like this may do the trick:

nlist.item(0).getAttributes().getNamedItem("north")
 
bryan lim
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
great! thanks it works perfectly.

if i only need to process the xml to extract value once, should i be using SAX?
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic