diff --git a/gpxpy/gpx.py b/gpxpy/gpx.py index 52bc7ea3..f88b0840 100644 --- a/gpxpy/gpx.py +++ b/gpxpy/gpx.py @@ -2564,7 +2564,7 @@ def to_xml(self, version=None, prettyprint=True): if self.version: version = self.version else: - version = '1.0' + version = '1.1' if version != '1.0' and version != '1.1': raise GPXException('Invalid version %s' % version) diff --git a/gpxpy/gpxfield.py b/gpxpy/gpxfield.py index a5a403f2..42090015 100644 --- a/gpxpy/gpxfield.py +++ b/gpxpy/gpxfield.py @@ -234,10 +234,11 @@ def from_xml(self, node, version): A string containing the email address. """ email_node = node.find(self.tag) + if email_node is None: + return '' email_id = email_node.get('id') email_domain = email_node.get('domain') - return '{0}@{1}'.format(email_id, email_domain) def to_xml(self, value, version, nsmap=None, prettyprint=True, indent=''): diff --git a/test.py b/test.py index c43c163f..d308b840 100644 --- a/test.py +++ b/test.py @@ -2917,6 +2917,48 @@ def test_write_read_extensions(self): print("Reading Track Point Extension") self.assertTrue(elements_equal(gpx.tracks[0].segments[0].points[0].extensions[0], root)) + def test_no_10_extensions(self): + namespace = '{gpx.py}' + nsmap = {'ext' : namespace[1:-1]} + root = mod_etree.Element(namespace + 'tag') + root.text = 'text' + root.tail = 'tail' + + gpx = mod_gpx.GPX() + gpx.nsmap = nsmap + + print("Inserting Waypoint Extension") + gpx.waypoints.append(mod_gpx.GPXWaypoint()) + gpx.waypoints[0].latitude = 5 + gpx.waypoints[0].longitude = 10 + gpx.waypoints[0].extensions.append(root) + + print("Inserting Metadata Extension") + gpx.metadata_extensions.append(root) + + print("Inserting GPX Extension") + gpx.extensions.append(root) + + print("Inserting Route Extension") + gpx.routes.append(mod_gpx.GPXRoute()) + gpx.routes[0].extensions.append(root) + + print("Inserting Track Extension") + gpx.tracks.append(mod_gpx.GPXTrack()) + gpx.tracks[0].extensions.append(root) + + print("Inserting Track Segment Extension") + gpx.tracks[0].segments.append(mod_gpx.GPXTrackSegment()) + gpx.tracks[0].segments[0].extensions.append(root) + + + print("Inserting Track Point Extension") + gpx.tracks[0].segments[0].points.append(mod_gpx.GPXTrackPoint(latitude=12, longitude=13)) + gpx.tracks[0].segments[0].points[0].extensions.append(root) + + xml = gpx.to_xml('1.0') + self.assertFalse('extension' in xml) + class LxmlTest(mod_unittest.TestCase): @mod_unittest.skipIf(mod_os.environ.get('XMLPARSER')!="LXML", "LXML not installed")