I have the following XML file containing GPS co-ordinates, and I was just wondering how I can extract the track latitudes and longitudes using Xpath in Java. So far I tried:
System.out.println(xpath.evaluate("/gpx/trk/trkseg/trkpt/@lat", doc));
but this only retrieves the first value? Please can someone tell me how to retrieve all the values in one go.
Many Thanks in advance.
<gpx xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="MapSource 6.11.3"
version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>...</metadata>
<wpt lat="40.653792" lon="-111.922379">...</wpt>
<wpt lat="40.658111" lon="-111.919564">...</wpt>
<wpt lat="40.659546" lon="-111.917527">...</wpt>
<wpt lat="40.595857" lon="-111.910294">...</wpt>
<wpt lat="40.657349" lon="-111.918721">...</wpt>
<trk>
<name>FromParking</name>
<extensions>...</extensions>
<trkseg>
<trkpt lat="40.653782" lon="-111.922365">
<ele>1224.376221</ele>
<time>2009-11-19T20:00:11Z</time>
</trkpt>
<trkpt lat="40.653786" lon="-111.922350">
<ele>1223.895508</ele>
<time>2009-11-19T20:00:13Z</time>
</trkpt>
<trkpt lat="40.654449" lon="-111.922073">
<ele>1224.376221</ele>
<time>2009-11-19T20:00:22Z</time>
</trkpt>
<trkpt lat="40.654509" lon="-111.921919">
<ele>1224.376221</ele>
<time>2009-11-19T20:00:25Z</time>
</trkpt>
<trkpt lat="40.654618" lon="-111.921700">
<ele>1224.856934</ele>
<time>2009-11-19T20:00:35Z</time>
</trkpt>