Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 165055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:51:12+00:00 2026-05-11T11:51:12+00:00

I’m trying to parse a GPX file . I tried it with JDOM, but

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:51:13+00:00Added an answer on May 11, 2026 at 11:51 am

    Here is my gpx reader. It ignores some of the tags but I hope it will help.

    package ch.perry.rando.geocode;  import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler;  /**  *  * @author perrym  */ public class GpxReader extends DefaultHandler {     private static final DateFormat TIME_FORMAT             = new SimpleDateFormat('yyyy-MM-dd'T'HH:mm:ss'Z'');      private List<Trackpoint> track = new ArrayList<Trackpoint>();     private StringBuffer buf = new StringBuffer();     private double lat;     private double lon;     private double ele;     private Date time;      public static Trackpoint[] readTrack(InputStream in) throws IOException {         try {             SAXParserFactory factory = SAXParserFactory.newInstance();             factory.setValidating(true);             SAXParser parser = factory.newSAXParser();             GpxReader reader = new GpxReader();             parser.parse(in, reader);             return reader.getTrack();         } catch (ParserConfigurationException e) {             throw new IOException(e.getMessage());         } catch (SAXException e) {             throw new IOException(e.getMessage());         }     }      public static Trackpoint[] readTrack(File file) throws IOException {         InputStream in = new FileInputStream(file);         try {             return readTrack(in);         } finally {             in.close();         }     }      @Override     public void startElement(String uri, String localName, String qName,             Attributes attributes) throws SAXException {         buf.setLength(0);         if (qName.equals('trkpt')) {             lat = Double.parseDouble(attributes.getValue('lat'));             lon = Double.parseDouble(attributes.getValue('lon'));         }     }      @Override     public void endElement(String uri, String localName, String qName)             throws SAXException {         if (qName.equals('trkpt')) {             track.add(Trackpoint.fromWGS84(lat, lon, ele, time));         } else if (qName.equals('ele')) {             ele = Double.parseDouble(buf.toString());         } else if (qName.equals('')) {             try {                 time = TIME_FORMAT.parse(buf.toString());             } catch (ParseException e) {                 throw new SAXException('Invalid time ' + buf.toString());             }         }     }      @Override     public void characters(char[] chars, int start, int length)             throws SAXException {         buf.append(chars, start, length);     }      private Trackpoint[] getTrack() {         return track.toArray(new Trackpoint[track.size()]);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
i want to parse a xhtml file and display in UITableView. what is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.