Skip to content
New issue

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

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

Already on GitHub? # to your account

GPX parsing not working with extension #254

Closed
Why-not-now opened this issue Feb 28, 2023 · 2 comments
Closed

GPX parsing not working with extension #254

Why-not-now opened this issue Feb 28, 2023 · 2 comments

Comments

@Why-not-now
Copy link

#open file
with open('test.gpx', 'r') as gpx_file:
    gpx = gpxpy.parse(gpx_file)

print(gpx.extensions)
print(gpx.metadata_extensions)

# save to a file
with open('output.gpx', 'w') as f:
    f.write(gpx.to_xml())

#open written file again
with open('output.gpx', 'r') as gpx_file:
    gpx_copy = gpxpy.parse(gpx_file)  # GPXXMLSyntaxException: Error parsing XML: not well-formed (invalid token): line 7, column 12

With the above attached code, when I read a file and save it, I cannot retrieve it again until I remove the extension. Getting either the extensions or the metadata extensions returns a blank list. I cannot seem to access the extension to remedy the problem.

For reference, this is the original GPX file (which can be opened)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="details.xsl"?>
<gpx
 version="1.1"
 creator="GaiaGPS for Android"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://www.topografix.com/GPX/1/1"
 xmlns:topografix="http://www.topografix.com/GPX/Private/TopoGrafix/0/1"
 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.topografix.com/GPX/Private/TopoGrafix/0/1 http://www.topografix.com/GPX/Private/TopoGrafix/0/1/topografix.xsd">
<trk>
<name><![CDATA[New Track 02/02/2023 01:00:00]]></name>
<desc></desc>
<number>13</number>
<extensions>
<line xmlns="http://www.topografix.com/GPX/gpx_style/0/2">
<color>5E7A8C</color>
</line>
</extensions>
<trkseg>
<trkpt lat="0.0000" lon="0.0000">
<ele>0.00</ele>
<time>2023-02-02T01:00:00Z</time>
</trkpt>
<trkpt lat="1.0000" lon="0.0000">
<ele>0.00</ele>
<time>2023-02-02T01:50:00Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>

And this is the written file

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:topografix="http://www.topografix.com/GPX/Private/TopoGrafix/0/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 http://www.topografix.com/GPX/Private/TopoGrafix/0/1 http://www.topografix.com/GPX/Private/TopoGrafix/0/1/topografix.xsd" version="1.1" creator="GaiaGPS for Android">
  <trk>
    <name>New Track 02/02/2023 01:00:00</name>
    <number>13</number>
    <extensions>
      <http://www.topografix.com/GPX/gpx_style/0/2:line>
        <http://www.topografix.com/GPX/gpx_style/0/2:color>5E7A8C</http://www.topografix.com/GPX/gpx_style/0/2:color>
      </http://www.topografix.com/GPX/gpx_style/0/2:line>
    </extensions>
    <trkseg>
      <trkpt lat="0.0" lon="0.0">
        <ele>0.0</ele>
        <time>2023-02-02T01:00:00Z</time>
      </trkpt>
      <trkpt lat="1.0" lon="0.0">
        <ele>0.0</ele>
        <time>2023-02-02T01:50:00Z</time>
      </trkpt>
    </trkseg>
  </trk>
</gpx>```
@ekspla
Copy link
Contributor

ekspla commented Mar 3, 2023

See, malformed xml issue #234

Workaround:

gpx.nsmap['gpx_style'] = 'http://www.topografix.com/GPX/gpx_style/0/2'

@Why-not-now
Copy link
Author

So ig it is a duplicate of #234, thank you for the workaround

@Why-not-now Why-not-now closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2023
@ekspla ekspla mentioned this issue Mar 5, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants