]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Improved the wrgpx library: Now the schema is validated and the script could have...
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 4 Dec 2009 21:29:34 +0000 (21:29 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 4 Dec 2009 21:29:34 +0000 (21:29 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@537 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/wradmin/lib/gpx_1_0.xsd [new file with mode: 0644]
wradmin/wradmin/lib/gpx_1_1.xsd [new file with mode: 0644]
wradmin/wradmin/lib/wrgpx.py

diff --git a/wradmin/wradmin/lib/gpx_1_0.xsd b/wradmin/wradmin/lib/gpx_1_0.xsd
new file mode 100644 (file)
index 0000000..63d4640
--- /dev/null
@@ -0,0 +1,227 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- GPX.xsd version 1.0 - For more information on GPX and this schema, visit http://www.topografix.com/gpx.asp -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gpx="http://www.topografix.com/GPX/1/0" targetNamespace="http://www.topografix.com/GPX/1/0" elementFormDefault="qualified">
+
+<!-- Main GPX definition -->
+
+  <xsd:element name="gpx">
+    <xsd:complexType>
+      <xsd:sequence>
+        <xsd:element name="name" type="xsd:string" minOccurs="0"/>             <!-- GPX file name -->
+        <xsd:element name="desc" type="xsd:string" minOccurs="0"/>             <!-- GPX file description -->
+        <xsd:element name="author" type="xsd:string" minOccurs="0"/>           <!-- GPX file author -->
+        <xsd:element name="email" type="gpx:emailType" minOccurs="0"/> <!-- GPX file author email -->
+        <xsd:element name="url" type="xsd:anyURI" minOccurs="0"/>              <!-- GPX file URL -->
+               <xsd:element name="urlname" type="xsd:string" minOccurs="0"/>
+        <xsd:element name="time" type="xsd:dateTime" minOccurs="0"/>           <!-- GPX file creation time -->
+        <xsd:element name="keywords" type="xsd:string" minOccurs="0"/>         <!-- GPX file keywords -->
+        <xsd:element name="bounds" type="gpx:boundsType" minOccurs="0"/>       <!-- GPX file bounding rect -->
+        <xsd:element name="wpt" minOccurs="0" maxOccurs="unbounded">
+          <xsd:complexType>
+            <xsd:sequence>     <!-- elements must appear in this order -->
+                         <!-- Position info -->
+              <xsd:element name="ele" type="xsd:decimal" minOccurs="0"/>
+              <xsd:element name="time" type="xsd:dateTime" minOccurs="0"/>
+                         <xsd:element name="magvar" type="gpx:degreesType" minOccurs="0"/>
+                         <xsd:element name="geoidheight" type="xsd:decimal" minOccurs="0"/>
+
+                         <!-- Description info -->
+                         <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="cmt" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="desc" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="src" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="url" type="xsd:anyURI" minOccurs="0"/>
+                         <xsd:element name="urlname" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="sym" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="type" type="xsd:string" minOccurs="0"/>
+
+                         <!-- Accuracy info -->
+                         <xsd:element name="fix" type="gpx:fixType" minOccurs="0"/>
+                         <xsd:element name="sat" type="xsd:nonNegativeInteger" minOccurs="0"/>
+                         <xsd:element name="hdop" type="xsd:decimal" minOccurs="0"/>
+                         <xsd:element name="vdop" type="xsd:decimal" minOccurs="0"/>
+                         <xsd:element name="pdop" type="xsd:decimal" minOccurs="0"/>
+                         <xsd:element name="ageofdgpsdata" type="xsd:decimal" minOccurs="0"/>
+                         <xsd:element name="dgpsid" type="gpx:dgpsStationType" minOccurs="0"/>
+
+                         <!-- you can add your own privately defined wpt elements at the end of the wpt -->
+              <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
+            </xsd:sequence>
+            <xsd:attribute name="lat" type="gpx:latitudeType" use="required"/>
+            <xsd:attribute name="lon" type="gpx:longitudeType" use="required"/>
+          </xsd:complexType>
+        </xsd:element>
+        <xsd:element name="rte" minOccurs="0" maxOccurs="unbounded">
+          <xsd:complexType>
+            <xsd:sequence>
+              <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="cmt" type="xsd:string" minOccurs="0"/>
+              <xsd:element name="desc" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="src" type="xsd:string" minOccurs="0"/>     <!-- the source of this data: "Garmin eTrex", "Map", etc -->
+                         <xsd:element name="url" type="xsd:anyURI" minOccurs="0"/>
+                         <xsd:element name="urlname" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="number" type="xsd:nonNegativeInteger" minOccurs="0"/>      <!-- GPS track number -->
+       <!--      <xsd:element name="type"                      type="xsd:string"       minOccurs="0"/> PROPOSED -->
+                         <!-- you can add your own privately defined rte elements at the end of the rte -->
+              <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
+              <xsd:element name="rtept" minOccurs="0" maxOccurs="unbounded">
+                <xsd:complexType>
+                  <xsd:sequence>       <!-- elements must appear in this order -->
+
+                                   <!-- Position info -->
+                    <xsd:element name="ele" type="xsd:decimal" minOccurs="0"/>
+                    <xsd:element name="time" type="xsd:dateTime" minOccurs="0"/>
+                                       <xsd:element name="magvar" type="gpx:degreesType" minOccurs="0"/>
+                                       <xsd:element name="geoidheight" type="xsd:decimal" minOccurs="0"/>
+
+                                       <!-- Description info -->
+                    <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="cmt" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="desc" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="src" type="xsd:string" minOccurs="0"/>
+                                       <xsd:element name="url" type="xsd:anyURI" minOccurs="0"/>
+                                   <xsd:element name="urlname" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="sym" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="type" type="xsd:string" minOccurs="0"/>
+
+                                       <!-- Accuracy info -->
+                                       <xsd:element name="fix" type="gpx:fixType" minOccurs="0"/>
+                                       <xsd:element name="sat" type="xsd:nonNegativeInteger" minOccurs="0"/>
+                                       <xsd:element name="hdop" type="xsd:decimal" minOccurs="0"/>
+                                       <xsd:element name="vdop" type="xsd:decimal" minOccurs="0"/>
+                                       <xsd:element name="pdop" type="xsd:decimal" minOccurs="0"/>
+                                       <xsd:element name="ageofdgpsdata" type="xsd:decimal" minOccurs="0"/>
+                                       <xsd:element name="dgpsid" type="gpx:dgpsStationType" minOccurs="0"/>
+
+                                       <!-- you can add your own privately defined rtept elements at the end of the rtept -->
+                    <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
+                  </xsd:sequence>
+                  <xsd:attribute name="lat" type="gpx:latitudeType" use="required"/>
+                  <xsd:attribute name="lon" type="gpx:longitudeType" use="required"/>
+                </xsd:complexType>
+              </xsd:element>
+            </xsd:sequence>
+          </xsd:complexType>
+        </xsd:element>
+        <xsd:element name="trk" minOccurs="0" maxOccurs="unbounded">
+          <xsd:complexType>
+            <xsd:sequence>
+              <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="cmt" type="xsd:string" minOccurs="0"/>
+              <xsd:element name="desc" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="src" type="xsd:string" minOccurs="0"/>     <!-- the source of this data: "Garmin eTrex", "Map", etc -->
+                         <xsd:element name="url" type="xsd:anyURI" minOccurs="0"/>
+                         <xsd:element name="urlname" type="xsd:string" minOccurs="0"/>
+                         <xsd:element name="number" type="xsd:nonNegativeInteger" minOccurs="0"/>      <!-- GPS track number -->
+       <!--      <xsd:element name="type"                      type="xsd:string"               minOccurs="0"/>  PROPOSED -->
+                         <!-- you can add your own privately defined trk elements at the end of the trk -->
+              <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
+              <xsd:element name="trkseg" minOccurs="0" maxOccurs="unbounded">
+                <xsd:complexType>
+                  <xsd:sequence>       <!-- elements must appear in this order -->
+                                   <xsd:element name="trkpt" minOccurs="0" maxOccurs="unbounded">
+                                         <xsd:complexType>
+                                           <xsd:sequence>      <!-- elements must appear in this order -->
+
+                                                 <!-- Position info -->
+                                                 <xsd:element name="ele" type="xsd:decimal" minOccurs="0"/>
+                                                 <xsd:element name="time" type="xsd:dateTime" minOccurs="0"/>
+                                                 <xsd:element name="course" type="gpx:degreesType" minOccurs="0"/>
+                                                 <xsd:element name="speed" type="xsd:decimal" minOccurs="0"/>
+                                                 <xsd:element name="magvar" type="gpx:degreesType" minOccurs="0"/>
+                                                 <xsd:element name="geoidheight" type="xsd:decimal" minOccurs="0"/>
+
+                                                 <!-- Description info -->
+                                                 <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+                                                 <xsd:element name="cmt" type="xsd:string" minOccurs="0"/>
+                                                 <xsd:element name="desc" type="xsd:string" minOccurs="0"/>
+                                                 <xsd:element name="src" type="xsd:string" minOccurs="0"/>
+                                                 <xsd:element name="url" type="xsd:anyURI" minOccurs="0"/>
+                                                 <xsd:element name="urlname" type="xsd:string" minOccurs="0"/>
+                                                 <xsd:element name="sym" type="xsd:string" minOccurs="0"/>
+                                                 <xsd:element name="type" type="xsd:string" minOccurs="0"/>
+
+                                                 <!-- Accuracy info -->
+                                                 <xsd:element name="fix" type="gpx:fixType" minOccurs="0"/>
+                                                 <xsd:element name="sat" type="xsd:nonNegativeInteger" minOccurs="0"/>
+                                                 <xsd:element name="hdop" type="xsd:decimal" minOccurs="0"/>
+                                                 <xsd:element name="vdop" type="xsd:decimal" minOccurs="0"/>
+                                                 <xsd:element name="pdop" type="xsd:decimal" minOccurs="0"/>
+                                                 <xsd:element name="ageofdgpsdata" type="xsd:decimal" minOccurs="0"/>
+                                                 <xsd:element name="dgpsid" type="gpx:dgpsStationType" minOccurs="0"/>
+
+                                                 <!-- you can add your own privately defined trkpt elements at the end of the trkpt -->
+                                                 <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
+                                           </xsd:sequence>
+                                           <xsd:attribute name="lat" type="gpx:latitudeType" use="required"/>
+                                           <xsd:attribute name="lon" type="gpx:longitudeType" use="required"/>
+                                         </xsd:complexType>
+                                   </xsd:element>
+                                 </xsd:sequence>
+                           </xsd:complexType>
+                         </xsd:element>
+            </xsd:sequence>
+          </xsd:complexType>
+        </xsd:element>
+               <!-- you can add your own privately defined elements at the end of the GPX file -->
+        <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
+      </xsd:sequence>
+      <xsd:attribute name="version" type="xsd:string" use="required" fixed="1.0"/>     <!-- version 1.0 -->
+      <xsd:attribute name="creator" type="xsd:string" use="required"/>
+    </xsd:complexType>
+  </xsd:element>
+
+  <!-- Other types used by GPX -->
+
+  <xsd:simpleType name="latitudeType">
+    <xsd:restriction base="xsd:decimal">
+      <xsd:minInclusive value="-90.0"/>
+      <xsd:maxInclusive value="90.0"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="longitudeType">
+    <xsd:restriction base="xsd:decimal">
+      <xsd:minInclusive value="-180.0"/>
+      <xsd:maxInclusive value="180.0"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="degreesType">  <!-- for bearing, heading, course.  Units are degrees, true -->
+    <xsd:restriction base="xsd:decimal">
+      <xsd:minInclusive value="0.0"/>
+      <xsd:maxInclusive value="360.0"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="fixType">
+    <xsd:restriction base="xsd:string">
+      <xsd:enumeration value="none"/>  <!-- none means GPS had no fix.  To signify "the fix info is unknown, leave out the <fix> tag entirely --> 
+      <xsd:enumeration value="2d"/>
+      <xsd:enumeration value="3d"/>
+      <xsd:enumeration value="dgps"/>
+      <xsd:enumeration value="pps"/>           <!-- military signal used -->
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="dgpsStationType">
+    <xsd:restriction base="xsd:integer">
+      <xsd:minInclusive value="0"/>
+      <xsd:maxInclusive value="1023"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:complexType name="boundsType">  <!-- bounding rect for data in file -->
+    <xsd:attribute name="minlat" type="gpx:latitudeType" use="required"/>
+    <xsd:attribute name="minlon" type="gpx:longitudeType" use="required"/>
+    <xsd:attribute name="maxlat" type="gpx:latitudeType" use="required"/>
+    <xsd:attribute name="maxlon" type="gpx:longitudeType" use="required"/>
+  </xsd:complexType>
+
+  <xsd:simpleType name="emailType">
+    <xsd:restriction base="xsd:string">
+      <xsd:pattern value="[\p{L}_]+(\.[\p{L}_]+)*@[\p{L}_]+(\.[\p{L}_]+)+"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+</xsd:schema>
\ No newline at end of file
diff --git a/wradmin/wradmin/lib/gpx_1_1.xsd b/wradmin/wradmin/lib/gpx_1_1.xsd
new file mode 100644 (file)
index 0000000..e2f074f
--- /dev/null
@@ -0,0 +1,784 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.topografix.com/GPX/1/1" targetNamespace="http://www.topografix.com/GPX/1/1" elementFormDefault="qualified">
+
+<xsd:annotation>
+ <xsd:documentation>
+  GPX schema version 1.1 - For more information on GPX and this schema, visit http://www.topografix.com/gpx.asp
+
+  GPX uses the following conventions: all coordinates are relative to the WGS84 datum.  All measurements are in metric units.
+ </xsd:documentation>
+</xsd:annotation>
+
+  <xsd:element name="gpx" type="gpxType">
+    <xsd:annotation>
+      <xsd:documentation>
+               GPX is the root element in the XML file.
+         </xsd:documentation>
+       </xsd:annotation>
+  </xsd:element>
+
+  <xsd:complexType name="gpxType">
+    <xsd:annotation>
+      <xsd:documentation>
+               GPX documents contain a metadata header, followed by waypoints, routes, and tracks.  You can add your own elements
+               to the extensions section of the GPX document.
+         </xsd:documentation>
+       </xsd:annotation>
+       <xsd:sequence>
+        <xsd:element name="metadata" type="metadataType" minOccurs="0">
+         <xsd:annotation>
+          <xsd:documentation>
+               Metadata about the file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+        <xsd:element name="wpt" type="wptType" minOccurs="0" maxOccurs="unbounded">
+         <xsd:annotation>
+          <xsd:documentation>
+               A list of waypoints.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+        <xsd:element name="rte" type="rteType" minOccurs="0" maxOccurs="unbounded">
+         <xsd:annotation>
+          <xsd:documentation>
+               A list of routes.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+        <xsd:element name="trk" type="trkType" minOccurs="0" maxOccurs="unbounded">
+         <xsd:annotation>
+          <xsd:documentation>
+               A list of tracks.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+        <xsd:element name="extensions" type="extensionsType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               You can add extend GPX by adding your own elements from another schema here.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+       </xsd:sequence>
+
+       <xsd:attribute name="version" type="xsd:string" use="required" fixed="1.1">
+     <xsd:annotation>
+      <xsd:documentation>
+               You must include the version number in your GPX document.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+       <xsd:attribute name="creator" type="xsd:string" use="required">
+     <xsd:annotation>
+      <xsd:documentation>
+               You must include the name or URL of the software that created your GPX document.  This allows others to
+               inform the creator of a GPX instance document that fails to validate.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+  </xsd:complexType>
+
+  <xsd:complexType name="metadataType">
+    <xsd:annotation>
+      <xsd:documentation>
+               Information about the GPX file, author, and copyright restrictions goes in the metadata section.  Providing rich,
+               meaningful information about your GPX files allows others to search for and use your GPS data.
+         </xsd:documentation>
+       </xsd:annotation>
+    <xsd:sequence>     <!-- elements must appear in this order -->
+     <xsd:element name="name" type="xsd:string" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               The name of the GPX file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+     <xsd:element name="desc" type="xsd:string" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               A description of the contents of the GPX file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+     <xsd:element name="author" type="personType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               The person or organization who created the GPX file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+     <xsd:element name="copyright" type="copyrightType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               Copyright and license information governing use of the file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+     <xsd:element name="link" type="linkType" minOccurs="0" maxOccurs="unbounded">
+      <xsd:annotation>
+       <xsd:documentation>
+               URLs associated with the location described in the file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+     <xsd:element name="time" type="xsd:dateTime" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               The creation date of the file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+     <xsd:element name="keywords" type="xsd:string" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               Keywords associated with the file.  Search engines or databases can use this information to classify the data.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+     <xsd:element name="bounds" type="boundsType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               Minimum and maximum coordinates which describe the extent of the coordinates in the file.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+
+        <xsd:element name="extensions" type="extensionsType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               You can add extend GPX by adding your own elements from another schema here.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+    </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="wptType">
+    <xsd:annotation>
+      <xsd:documentation>
+               wpt represents a waypoint, point of interest, or named feature on a map.
+         </xsd:documentation>
+       </xsd:annotation>
+    <xsd:sequence>     <!-- elements must appear in this order -->
+         <!-- Position info -->
+      <xsd:element name="ele" type="xsd:decimal" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Elevation (in meters) of the point.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+      <xsd:element name="time" type="xsd:dateTime" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Creation/modification timestamp for element. Date and time in are in Univeral Coordinated Time (UTC), not local time! Conforms to ISO 8601 specification for date/time representation. Fractional seconds are allowed for millisecond timing in tracklogs. 
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="magvar" type="degreesType" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Magnetic variation (in degrees) at the point
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="geoidheight" type="xsd:decimal" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Height (in meters) of geoid (mean sea level) above WGS84 earth ellipsoid.  As defined in NMEA GGA message.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+
+         <!-- Description info -->
+         <xsd:element name="name" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       The GPS name of the waypoint. This field will be transferred to and from the GPS. GPX does not place restrictions on the length of this field or the characters contained in it. It is up to the receiving application to validate the field before sending it to the GPS.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="cmt" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       GPS waypoint comment. Sent to GPS as comment. 
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="desc" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       A text description of the element. Holds additional information about the element intended for the user, not the GPS.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="src" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Source of data. Included to give user some idea of reliability and accuracy of data.  "Garmin eTrex", "USGS quad Boston North", e.g.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+      <xsd:element name="link" type="linkType" minOccurs="0" maxOccurs="unbounded">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Link to additional information about the waypoint.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="sym" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Text of GPS symbol name. For interchange with other programs, use the exact spelling of the symbol as displayed on the GPS.  If the GPS abbreviates words, spell them out.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="type" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Type (classification) of the waypoint.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+
+         <!-- Accuracy info -->
+         <xsd:element name="fix" type="fixType" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Type of GPX fix.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="sat" type="xsd:nonNegativeInteger" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Number of satellites used to calculate the GPX fix.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="hdop" type="xsd:decimal" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Horizontal dilution of precision.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="vdop" type="xsd:decimal" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Vertical dilution of precision.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="pdop" type="xsd:decimal" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Position dilution of precision.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="ageofdgpsdata" type="xsd:decimal" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Number of seconds since last DGPS update.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="dgpsid" type="dgpsStationType" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       ID of DGPS station used in differential correction.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+
+        <xsd:element name="extensions" type="extensionsType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               You can add extend GPX by adding your own elements from another schema here.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+    </xsd:sequence>
+
+    <xsd:attribute name="lat" type="latitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The latitude of the point.  Decimal degrees, WGS84 datum.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+    <xsd:attribute name="lon" type="longitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The latitude of the point.  Decimal degrees, WGS84 datum.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+  </xsd:complexType>
+
+  <xsd:complexType name="rteType">
+    <xsd:annotation>
+      <xsd:documentation>
+               rte represents route - an ordered list of waypoints representing a series of turn points leading to a destination.
+         </xsd:documentation>
+       </xsd:annotation>
+    <xsd:sequence>
+      <xsd:element name="name" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       GPS name of route.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="cmt" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       GPS comment for route.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+      <xsd:element name="desc" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Text description of route for user.  Not sent to GPS.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="src" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Source of data. Included to give user some idea of reliability and accuracy of data.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+      <xsd:element name="link" type="linkType" minOccurs="0" maxOccurs="unbounded">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Links to external information about the route.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="number" type="xsd:nonNegativeInteger" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       GPS route number.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="type" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Type (classification) of route.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+
+        <xsd:element name="extensions" type="extensionsType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               You can add extend GPX by adding your own elements from another schema here.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+      <xsd:element name="rtept" type="wptType" minOccurs="0" maxOccurs="unbounded">
+         <xsd:annotation>
+          <xsd:documentation>
+               A list of route points.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+    </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="trkType">
+    <xsd:annotation>
+      <xsd:documentation>
+               trk represents a track - an ordered list of points describing a path.
+         </xsd:documentation>
+       </xsd:annotation>
+    <xsd:sequence>
+      <xsd:element name="name" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       GPS name of track.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="cmt" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       GPS comment for track.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+      <xsd:element name="desc" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       User description of track.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="src" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Source of data. Included to give user some idea of reliability and accuracy of data.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+      <xsd:element name="link" type="linkType" minOccurs="0" maxOccurs="unbounded">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Links to external information about track.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="number" type="xsd:nonNegativeInteger" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       GPS track number.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+         <xsd:element name="type" type="xsd:string" minOccurs="0">
+               <xsd:annotation>
+                 <xsd:documentation>
+                       Type (classification) of track.
+                 </xsd:documentation>
+               </xsd:annotation>
+         </xsd:element>
+
+        <xsd:element name="extensions" type="extensionsType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               You can add extend GPX by adding your own elements from another schema here.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+  
+     <xsd:element name="trkseg" type="trksegType" minOccurs="0" maxOccurs="unbounded">
+      <xsd:annotation>
+       <xsd:documentation>
+               A Track Segment holds a list of Track Points which are logically connected in order. To represent a single GPS track where GPS reception was lost, or the GPS receiver was turned off, start a new Track Segment for each continuous span of track data.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+    </xsd:sequence>
+  </xsd:complexType>
+  <xsd:complexType name="extensionsType">
+   <xsd:annotation>
+    <xsd:documentation>
+        You can add extend GPX by adding your own elements from another schema here.
+    </xsd:documentation>
+   </xsd:annotation>
+    <xsd:sequence>
+        <xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded">
+          <xsd:annotation>
+               <xsd:documentation>
+                You can add extend GPX by adding your own elements from another schema here.
+               </xsd:documentation>
+          </xsd:annotation>
+        </xsd:any>
+    </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="trksegType">
+   <xsd:annotation>
+    <xsd:documentation>
+        A Track Segment holds a list of Track Points which are logically connected in order. To represent a single GPS track where GPS reception was lost, or the GPS receiver was turned off, start a new Track Segment for each continuous span of track data.
+    </xsd:documentation>
+   </xsd:annotation>
+   <xsd:sequence>      <!-- elements must appear in this order -->
+        <xsd:element name="trkpt" type="wptType" minOccurs="0" maxOccurs="unbounded">
+      <xsd:annotation>
+       <xsd:documentation>
+               A Track Point holds the coordinates, elevation, timestamp, and metadata for a single point in a track.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+
+        <xsd:element name="extensions" type="extensionsType" minOccurs="0">
+      <xsd:annotation>
+       <xsd:documentation>
+               You can add extend GPX by adding your own elements from another schema here.
+          </xsd:documentation>
+         </xsd:annotation>
+        </xsd:element>
+    </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="copyrightType">
+   <xsd:annotation>
+    <xsd:documentation>
+        Information about the copyright holder and any license governing use of this file.  By linking to an appropriate license,
+        you may place your data into the public domain or grant additional usage rights.
+    </xsd:documentation>
+   </xsd:annotation>
+   <xsd:sequence>      <!-- elements must appear in this order -->
+    <xsd:element name="year" type="xsd:gYear" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               Year of copyright.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+    <xsd:element name="license" type="xsd:anyURI" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               Link to external file containing license text.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+   </xsd:sequence>
+   <xsd:attribute name="author" type="xsd:string" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               Copyright holder (TopoSoft, Inc.)
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+  </xsd:complexType>
+
+  <xsd:complexType name="linkType">
+   <xsd:annotation>
+    <xsd:documentation>
+        A link to an external resource (Web page, digital photo, video clip, etc) with additional information.
+    </xsd:documentation>
+   </xsd:annotation>
+   <xsd:sequence>      <!-- elements must appear in this order -->
+    <xsd:element name="text" type="xsd:string" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               Text of hyperlink.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+    <xsd:element name="type" type="xsd:string" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               Mime type of content (image/jpeg)
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+   </xsd:sequence>
+   <xsd:attribute name="href" type="xsd:anyURI" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               URL of hyperlink.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+  </xsd:complexType>
+
+  <xsd:complexType name="emailType">
+   <xsd:annotation>
+    <xsd:documentation>
+        An email address.  Broken into two parts (id and domain) to help prevent email harvesting.
+    </xsd:documentation>
+   </xsd:annotation>
+   <xsd:attribute name="id" type="xsd:string" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               id half of email address (billgates2004)
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+   <xsd:attribute name="domain" type="xsd:string" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               domain half of email address (hotmail.com)
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+  </xsd:complexType>
+
+  <xsd:complexType name="personType">
+   <xsd:annotation>
+    <xsd:documentation>
+        A person or organization.
+    </xsd:documentation>
+   </xsd:annotation>
+    <xsd:sequence>     <!-- elements must appear in this order -->
+      <xsd:element name="name" type="xsd:string" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               Name of person or organization.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+      <xsd:element name="email" type="emailType" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               Email address.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+      <xsd:element name="link" type="linkType" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               Link to Web site or other external information about person.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+       </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="ptType">
+   <xsd:annotation>
+    <xsd:documentation>
+        A geographic point with optional elevation and time.  Available for use by other schemas.
+    </xsd:documentation>
+   </xsd:annotation>
+   <xsd:sequence>      <!-- elements must appear in this order -->
+    <xsd:element name="ele" type="xsd:decimal" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               The elevation (in meters) of the point.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+    <xsd:element name="time" type="xsd:dateTime" minOccurs="0">
+        <xsd:annotation>
+         <xsd:documentation>
+               The time that the point was recorded.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:element>
+   </xsd:sequence>
+    <xsd:attribute name="lat" type="latitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The latitude of the point.  Decimal degrees, WGS84 datum.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+    <xsd:attribute name="lon" type="longitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The latitude of the point.  Decimal degrees, WGS84 datum.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+  </xsd:complexType>
+
+  <xsd:complexType name="ptsegType">
+   <xsd:annotation>
+    <xsd:documentation>
+        An ordered sequence of points.  (for polygons or polylines, e.g.)
+    </xsd:documentation>
+   </xsd:annotation>
+   <xsd:sequence>      <!-- elements must appear in this order -->
+        <xsd:element name="pt" type="ptType" minOccurs="0" maxOccurs="unbounded">
+          <xsd:annotation>
+               <xsd:documentation>
+                Ordered list of geographic points.
+               </xsd:documentation>
+          </xsd:annotation>
+        </xsd:element>
+   </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="boundsType">
+   <xsd:annotation>
+    <xsd:documentation>
+        Two lat/lon pairs defining the extent of an element.
+    </xsd:documentation>
+   </xsd:annotation>
+    <xsd:attribute name="minlat" type="latitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The minimum latitude.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+    <xsd:attribute name="minlon" type="longitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The minimum longitude.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+    <xsd:attribute name="maxlat" type="latitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The maximum latitude.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+    <xsd:attribute name="maxlon" type="longitudeType" use="required">
+        <xsd:annotation>
+         <xsd:documentation>
+               The maximum longitude.
+         </xsd:documentation>
+        </xsd:annotation>
+       </xsd:attribute>
+  </xsd:complexType>
+
+
+  <xsd:simpleType name="latitudeType">
+        <xsd:annotation>
+         <xsd:documentation>
+               The latitude of the point.  Decimal degrees, WGS84 datum.
+         </xsd:documentation>
+        </xsd:annotation>
+    <xsd:restriction base="xsd:decimal">
+      <xsd:minInclusive value="-90.0"/>
+      <xsd:maxInclusive value="90.0"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="longitudeType">
+        <xsd:annotation>
+         <xsd:documentation>
+               The longitude of the point.  Decimal degrees, WGS84 datum.
+         </xsd:documentation>
+        </xsd:annotation>
+    <xsd:restriction base="xsd:decimal">
+      <xsd:minInclusive value="-180.0"/>
+      <xsd:maxExclusive value="180.0"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="degreesType">
+        <xsd:annotation>
+         <xsd:documentation>
+               Used for bearing, heading, course.  Units are decimal degrees, true (not magnetic).
+         </xsd:documentation>
+        </xsd:annotation>
+    <xsd:restriction base="xsd:decimal">
+      <xsd:minInclusive value="0.0"/>
+      <xsd:maxExclusive value="360.0"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="fixType">
+        <xsd:annotation>
+         <xsd:documentation>
+               Type of GPS fix.  none means GPS had no fix.  To signify "the fix info is unknown, leave out fixType entirely. pps = military signal used
+         </xsd:documentation>
+        </xsd:annotation>
+    <xsd:restriction base="xsd:string">
+      <xsd:enumeration value="none"/>
+      <xsd:enumeration value="2d"/>
+      <xsd:enumeration value="3d"/>
+      <xsd:enumeration value="dgps"/>
+      <xsd:enumeration value="pps"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="dgpsStationType">
+   <xsd:annotation>
+    <xsd:documentation>
+        Represents a differential GPS station.
+    </xsd:documentation>
+   </xsd:annotation>
+    <xsd:restriction base="xsd:integer">
+      <xsd:minInclusive value="0"/>
+      <xsd:maxInclusive value="1023"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+</xsd:schema>
\ No newline at end of file
index 899ce64b80ad27a88ad96bdbacb58fad44f10194..f1ae3bd82d616ba9a420080dc4866b83059050da 100644 (file)
@@ -7,7 +7,8 @@ a map automatically."""
 
 import mapnik
 import datetime
-from xml.etree.cElementTree import parse
+import os
+from lxml import etree
 
 
 class MetaData:
@@ -57,54 +58,34 @@ class Hint:
                self.line_nr = line_nr
 
 
-def parse_wrgpx(filename):
+def parse_wrgpx(filename=None, string=None):
        """Parses a WRGPX file and returns a tuple of a data structure representing the content of the GPX file
-       and a list of Hint classes. If the file is not well-formed, an exception is raised."""
+       and a list of Hint classes. If the file is not well-formed or not an GPX 1.1 file, an etree.XMLSyntaxError exception is raised."""
        hints = []
        wrgpx = WrGpx()
 
        ns = '{http://www.topografix.com/GPX/1/1}'
 
-       def parse_link(el):
-               if len(el.items()) == 0: hints.append(Hint("XML element link does not have an attribute 'href'.", 2))
-               elif len(el.items()) > 1: raise Exception("XML element link has more than one attribute (should only have 'href').")
-               elif el.items()[0][0] != 'href': raise Exception("XML attribute '%s' is not allowed within XML element link (only 'href' is allowed)." % el.items()[0][0])
-               else: return el.items()[0][1]
-               return None
-       
        def parse_wpt(element):
                waypoint = Waypoint()
-               for k, v in element.items():
-                       if k == 'lat': waypoint.lat = float(v)
-                       elif k == 'lon': waypoint.lon = float(v)
-                       else: raise Exception("Unexpected XML attribute '%s' of 'wpt'." % k)
+               waypoint.lat = float(element.attrib['lat'])
+               waypoint.lon = float(element.attrib['lon'])
                for el in element:
                        if el.tag == ns+'ele': waypoint.ele = float(el.text)
-                       elif el.tag == ns+'time': pass
-                       elif el.tag == ns+'magvar': pass
-                       elif el.tag == ns+'geoidheight': pass
                        elif el.tag == ns+'name': waypoint.name = el.text
-                       elif el.tag == ns+'cmt': pass
                        elif el.tag == ns+'desc': waypoint.desc = el.text
-                       elif el.tag == ns+'src': pass
-                       elif el.tag == ns+'link': waypoint.link = parse_link(el)
-                       elif el.tag == ns+'sym': pass
+                       elif el.tag == ns+'link': waypoint.link = el.attrib['href']
                        elif el.tag == ns+'type': waypoint.type = el.text
-                       elif el.tag == ns+'fix': pass
-                       elif el.tag == ns+'sat': pass
-                       elif el.tag == ns+'hdop': pass
-                       elif el.tag == ns+'vdop': pass
-                       elif el.tag == ns+'pdop': pass
-                       elif el.tag == ns+'ageofdgpsdata': pass
-                       elif el.tag == ns+'dgpsid': pass
-                       elif el.tag == ns+'extensions': pass
-                       else: raise Exception("Unexpected XML element '%s' within '%s'." % (el.tag, element.tag))
                return waypoint
 
-       xml = parse(open(filename, 'rb'))
-       root = xml.getroot()
-       if root.tag != ns + 'gpx':
-               raise Exception("XML root element '%s' has to be '%sgpx'!" % (root.tag, ns))
+       schema = etree.XMLSchema(file=os.path.dirname(os.path.realpath(__file__)) + os.sep + 'gpx_1_1.xsd')
+       parser = etree.XMLParser(schema=schema)
+       if not string is None: root = etree.fromstring(string, parser)
+       else: 
+               # xml = etree.parse(open(filename, 'rb'), parser)
+               xml = etree.parse(filename, parser)
+               root = xml.getroot()
+       assert root.tag == ns + 'gpx' # Nothing else should be possible after validation
        
        wrgpx_has_metadata = False
        for element in root:
@@ -112,44 +93,26 @@ def parse_wrgpx(filename):
                if element.tag == ns+'metadata':
                        wrgpx_has_metadata = True
                        for el in element:
-                               if el.tag == ns+'name':
-                                       wrgpx.metadata.name = el.text
-                               elif el.tag == ns+'desc':
-                                       wrgpx.metadata.desc = el.text
+                               if el.tag == ns+'name': wrgpx.metadata.name = el.text
+                               elif el.tag == ns+'desc': wrgpx.metadata.desc = el.text
                                elif el.tag == ns+'author':
                                        for e in el:
                                                if e.tag == ns+'name': wrgpx.metadata.author = e.text
                                                elif e.tag == ns+'email':
-                                                       mail_id = None
-                                                       mail_domain = None
-                                                       for k, v in e.items():
-                                                               if k == 'id': mail_id = v
-                                                               elif k == 'domain': mail_domain = v
-                                                               else: raise Exception("Unexpected XML attribute '%s' of email." % k)
-                                                       if mail_id is None: raise Exception("Missing XML attribute 'id' of email.")
-                                                       if mail_domain is None: raise Exception("Missing XML attribute 'domain' of email.")
-                                                       wrgpx.metadata.author_email = mail_id + '@' + mail_domain
-                                               else: raise Exception("Unexpected XML element '%s' within author." % e.tag)
+                                                       wrgpx.metadata.author_email = e.attrib['id'] + '@' + e.attrib['domain']
                                elif el.tag == ns+'copyright':
                                        for e in el:
                                                if e.tag == ns+'year': wrgpx.metadata.copyright_year = int(e.text)
                                                elif e.tag == ns+'license': wrgpx.metadata.license = e.text
-                                               else: raise Exception("Unexpected XML element '%s' within copyright." % e.tag)
-                               elif el.tag == ns+'link': wrgpx.metadata.link = parse_link(el)
+                               elif el.tag == ns+'link': wrgpx.metadata.link = el.attrib['href']
                                elif el.tag == ns+'time':
-                                       wrgpx.metadata.time = datetime.datetime.strptime('2008-11-10T20:44:52Z', '%Y-%m-%dT%H:%M:%SZ')
+                                       wrgpx.metadata.time = datetime.datetime.strptime(el.text, '%Y-%m-%dT%H:%M:%SZ') # '2008-11-10T20:44:52Z'
                                elif el.tag == ns+'bounds':
-                                       for k, v in el.items():
-                                               if k == 'minlat': wrgpx.metadata.minlat = float(v)
-                                               elif k == 'minlon': wrgpx.metadata.minlon = float(v)
-                                               elif k == 'maxlat': wrgpx.metadata.maxlat = float(v)
-                                               elif k == 'maxlon': wrgpx.metadata.maxlon = float(v)
-                                               else: raise Exception("Unexpected XML attribute '%s' of bounds." % k)
-                                       if wrgpx.metadata.minlat is None or wrgpx.metadata.minlon is None or wrgpx.metadata.maxlat is None or wrgpx.metadata.maxlon is None:
-                                               raise Exception("Not all of the attributes 'minlat', 'minlon', 'maxlat', 'maxlon' present in XML element 'bounds'.")
-                               elif el.tag == ns+'extensions':
-                                       hints.append(Hint("XML element extensions within XML element metadata is not used by WRGPX.", 1))
-                               else: raise Exception("Unexpected XML element '%s' within metadata." % el.tag)
+                                       wrgpx.metadata.minlat = float(el.attrib['minlat'])
+                                       wrgpx.metadata.minlon = float(el.attrib['minlon'])
+                                       wrgpx.metadata.maxlat = float(el.attrib['maxlat'])
+                                       wrgpx.metadata.maxlon = float(el.attrib['maxlon'])
+                               elif el.tag == ns+'extensions': hints.append(Hint("XML element extensions within XML element metadata is not used by WRGPX.", 1))
 
                # Waypoints
                elif element.tag == ns+'wpt':
@@ -165,27 +128,22 @@ def parse_wrgpx(filename):
                        track = Track()
                        for el in element:
                                if el.tag == ns+'name': track.name = el.text
-                               elif el.tag == ns+'cmt': pass
                                elif el.tag == ns+'desc': track.desc = el.text
-                               elif el.tag == ns+'src': pass
-                               elif el.tag == ns+'link': track.link = parse_link(el)
-                               elif el.tag == ns+'number': pass
+                               elif el.tag == ns+'link': track.link = el.attrib['href']
                                elif el.tag == ns+'type': track.type = el.text
-                               elif el.tag == ns+'extensions': pass
                                elif el.tag == ns+'trkseg': 
                                        for e in el:
                                                if e.tag == ns+'trkpt':
                                                        trkpt = parse_wpt(e)
                                                        track.points.append((trkpt.lat, trkpt.lon, trkpt.ele))
-                                               elif e.tag == ns+'extensions': pass
-                                               else: raise Exception("Unexpected XML element '%s' within 'trkseg'." % e.tag)
-                               else: raise Exception("Unexpected XML element '%s' within wpt." % el.tag)
+                                               elif e.tag == ns+'extensions': hints.append(Hint("XML element extensions within XML element trkpt is not used by WRGPX.", 1))
                        wrgpx.tracks.append(track)
 
                # Extensions
                elif element.tag == ns+'extensions':
                        hints.append(Hint("GPX file has a 'extensions' element. This is not used in WRGPX.", 1))
 
-               else: raise Exception("Unexpected XML element '%s'. It has to be one of '%s', '%s' or '%s'." % (element.tag, ns+'metadata', ns+'wpt', ns+'trk'))
        if not wrgpx_has_metadata: hints.append(Hint("GPX file has a no metadata (like author, ...).", 2))
        return (wrgpx, hints)
+
+