I am extracting data from gpx files using gpxpy. Data example:
<?xml version="1.0" encoding="UTF-8"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
version="1.1"
creator="xyz3">
<metadata>
<name>Cubieres-St.Paul</name>
<desc>Export from GpsPrune</desc>
</metadata>
<trk>
...
</trk>
</gpx>
The code goes like this:
def gpxinfo(gpx): # gpx =: class gpxpy.gpx.GPX
"extract from GPX-file"
gpxname = "No gpxname"
description = "No description"
if gpx.name:
gpxname = gpx.name
if gpx.description:
description = gpx.description
return {'gpxname': gpxname,
'description': description}
Now, I want to add the <metadata>..</metadata>
section for other gpx files where it is missing.
The problem in gpxpy for me is to insert the ‘name’ and ‘desc’ tags into the internal data structure that gpxpy builds up when parsing the file.
I don’t come to grips even by looking into the gpxpy source code.