slightly more robust XML parsing of the GPX track (elevation is now
[utils] / gps / src / org / wamblee / gpx / GpxParser.java
index 500091b3bb02adf2ef4e4cdf4923c6f442715561..fe675ce670abd5092259baceba2ab79b2f26a86c 100644 (file)
 
 package org.wamblee.gpx;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;
 
-import javax.xml.parsers.ParserConfigurationException;
-
 import org.dom4j.Document;
 import org.dom4j.Element;
 import org.wamblee.gps.track.Track;
 import org.wamblee.gps.track.TrackPoint;
 import org.wamblee.xml.DomUtils;
-import org.xml.sax.SAXException;
+import org.wamblee.xml.XMLException;
 
 /**
  * Parser for GPX tracks.  
  */
 public class GpxParser {
     
+    private static final String SCHEMA_RESOURCE = "gpx.xsd";
+    
     public GpxParser() { 
         // Empty.
     }
     
-    public Track parse(InputStream aIs) throws SAXException, ParserConfigurationException, IOException { 
+    public Track parse(InputStream aIs) throws XMLException { 
         Document doc = DomUtils.convert(DomUtils.read(aIs));
         return parse(doc);
     }
@@ -63,7 +62,11 @@ public class GpxParser {
         //System.out.println(trkpt.asXML() + "|\n"); 
         double latitude = new Double(trkpt.attributeValue("lat"));
         double longitude = new Double(trkpt.attributeValue("lon"));
-        double elevation = new Double(trkpt.elementText("ele"));
+        Element ele = trkpt.element("ele");
+        double elevation = 0.0;
+        if ( ele != null ) { 
+            elevation = new Double(ele.getText());
+        }
         //System.out.println("  lat = " + lat + " lon = " + lon + " ele = " + ele);
         return new TrackPoint(latitude, longitude, elevation);
     }