Hi
are there some Java API for parsing GPX files? I need to parse many GPX files into our own data structure (our own database).
Thx 4 help
Buju
Hi
are there some Java API for parsing GPX files? I need to parse many GPX files into our own data structure (our own database).
Thx 4 help
Buju
I'm not aware of any library specialized in parsing GPX files, but since GPX is XML you can use your preferred Java XML parser for reading it.
The GPX format is documented here (includes XSD schema):
http://www.topografix.com/gpx.asp
After some research, there is really no Java API/Lib for parsing GPX files, but I found a nice approach for parsing it using JAXB
Using this Tutorial: http://www.oracle.com/technetwork/articles/javase/index-140168.html
Steps:
1. Download GPX 1.0 and 1.1 Schema file (xsd)
2. Generate Java File from it using Eclipse Plugin
3. Init JAXBContext with package name of generated GPX java files (mine was "topografix.gpx.schema10")
4. Parse GPX File
JAXBContext jc = JAXBContext.newInstance("topografix.gpx.schema10");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Gpx root = (Gpx) unmarshaller.unmarshal(new File("sample.gpx"));
List<Trk> tracks = root.getTrk();
....
Hi,
Very nice. However, I needed to do:
GpxType gpx = null;
try {
JAXBContext jc = JAXBContext.newInstance(PACKAGE_NAME);
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement<GpxType> root = (JAXBElement<GpxType>)unmarshaller
.unmarshal(new File(TEST_FILE));
gpx = root.getValue();
} catch(JAXBException ex) {
// TODO
}
List<TrkType> tracks = gpx.getTrk();
for(TrkType track : tracks) {
System.out.println(track.getName());
}
BTW I used http://www.topografix.com/GPX/1/1.
-Ken