to_xml removes metadata extensions without the name tag present
CyrilSLi opened this issue · 1 comments
CyrilSLi commented
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 commented
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.