Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_xml removes metadata extensions without the name tag present #280

Open
CyrilSLi opened this issue Apr 25, 2024 · 1 comment
Open

to_xml removes metadata extensions without the name tag present #280

CyrilSLi opened this issue Apr 25, 2024 · 1 comment

Comments

@CyrilSLi
Copy link

CyrilSLi commented Apr 25, 2024

Test code:

import gpxpy
gpx = gpxpy.parse("""\
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="test">
  <metadata>
    <name>Name</name>
    <extensions>
      <tag>value</tag>
    </extensions>
  </metadata>
  <trk>
  </trk>
</gpx>""")
print(gpx.metadata_extensions) # [<Element 'tag' at 0x123456789>]
gpx.name = None
print(gpx.to_xml())
"""
<?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="test">
  <trk>
  </trk>
</gpx>
"""
gpx = gpxpy.parse(gpx.to_xml())
print(gpx.metadata_extensions) # []
@CyrilSLi
Copy link
Author

I am pretty sure that the problem lies within gpx_fields_to_xml in gpxfield.py, with value = getattr(instance, gpx_field.name) being a likely culprit, however I am not familiar with the variables used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant