Skip to content

Links in XML not properly encoded #283

@krzys-h

Description

@krzys-h

I'm trying to alter a .gpx file which contains a link along the lines of:

<?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">
  <metadata>
    <link href="https://example.com/?this=is&amp;an=example">
      <text>some text</text>
    </link>
  </metadata>
</gpx>

After modifying the file using gpxpy and exporting with to_xml(), this turns into:

<?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">
  <metadata>
    <link href="https://example.com/?this=is&an=example">
      <text>some text</text>
    </link>
  </metadata>
</gpx>

which is not valid XML (as even the GitHub markdown highlighting shows) - unlike HTML5, you need to always encode the &amp;. This causes the file to fail to import in gpxpod (and maybe other gpx viewers as well)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions