tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
988 stars 223 forks source link

extensions with complex children are not parsed #73

Closed tstanis closed 6 years ago

tstanis commented 7 years ago

For example, consider these extensions:

<extensions>
  <gpxtpx:TrackPointExtension>
    <gpxtpx:atemp>29</gpxtpx:atemp>
    <gpxtpx:hr>89</gpxtpx:hr>
    <gpxtpx:cad>83</gpxtpx:cad>
  </gpxtpx:TrackPointExtension>
</extensions>

The problem is that GPXExtensionField assumes that all extensions are simple values, and doesn't parse the children:

https://github.com/tkrajina/gpxpy/blob/master/gpxpy/gpxfield.py#L254

I think the fix is to make the extensions into objects, but this breaks API compatibility as some users are expecting that extensions['myextension'] returns a string value, not an object. One way to deal with this would be to have extensions have a new field called subExtensions that contains the children.

What do you think?

tkrajina commented 7 years ago

I'll quote from README.md:

WARNING: The only part of the GPX standard which is not completely implemented are GPX extensions. The API for GPX extensions will change in future versions!!!

I was thinking on a customizable extensions helper which need to specify a serializer and underializer functions to user's own custom object. Then, those will be executed during parsing or .to_xml().

Everything not (de)serialized with this serialized will be in the existing extensions map. This will not break the existing versions.

Unfortunately, at the moment I don't have the time to implement that :( But, if somebody is willing to implement this, I'm willing to help/discuss/merge.