I’m trying to parse a GPX file. I tried it with JDOM, but it does not work very well.
SAXBuilder builder = new SAXBuilder(); Document document = builder.build(filename); Element root = document.getRootElement(); System.out.println('Root:\t' + root.getName()); List<Element> listTrks = root.getChildren('trk'); System.out.println('Count trk:\t' + listTrks.size()); for (Element tmpTrk : listTrks) { List<Element> listTrkpts = tmpTrk.getChildren('trkpt'); System.out.println('Count pts:\t' + listTrkpts.size()); for (Element tmpTrkpt : listTrkpts) { System.out.println(tmpTrkpt.getAttributeValue('lat') + ':' + tmpTrkpt.getAttributeValue('lat')); } }
I opened the example file (CC-BY-SA OpenStreetMap) and the output is just:
Root: gpx
Count trk: 0
What can I do? Should I us a SAXParserFactory (javax.xml.parsers.SAXParserFactory) and implement a Handler class?
Here is my gpx reader. It ignores some of the tags but I hope it will help.