jenetics / jpx

JPX - Java GPX library
Apache License 2.0
202 stars 30 forks source link

Cannot read amazfit gpx track #170

Closed Nymerea closed 10 months ago

Nymerea commented 1 year ago

Hi, I cannot parse a gpx file imported from my amazfit watch. java.io.InvalidObjectException: Invalid GPX: Invalid value for 'version': Unknown version string: '7.7.5-play'.

here is an exemple of the gpx file :

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:ns2="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:ns1="http://www.cluetrust.com/XML/GPXDATA/1/0" creator="Zepp App" version="7.7.5-play">
    <trk>
        <name><![CDATA[20230507 mile iles]]></name>
        <trkseg>
            <trkpt lat="45.5898" lon="-73.67509">
                <ele>42.05</ele>
                <time>2023-05-07T18:34:59Z</time>
                    <extensions>
                        <ns3:TrackPointExtension>
                            <ns3:speed>2.3255813</ns3:speed>
                            <ns3:cad>0.0</ns3:cad>
                            <ns3:hr>72</ns3:hr>
                        </ns3:TrackPointExtension>
                    </extensions>
            </trkpt>
            <trkpt lat="45.589817" lon="-73.67511">
                <ele>42.05</ele>
                <time>2023-05-07T18:34:59Z</time>
                    <extensions>
                        <ns3:TrackPointExtension>
                            <ns3:speed>2.3255813</ns3:speed>
                            <ns3:cad>0.0</ns3:cad>
                            <ns3:hr>72</ns3:hr>
                        </ns3:TrackPointExtension>
                    </extensions>
            </trkpt>
        </trkseg>
    </trk>
</gpx>
jenetics commented 1 year ago

The version attribute determines the GPX version, which is either "1.0" or "1.1", according to the GPX-standard. The amazfit watch is creating an invalid GPX file.

You have to fix the version string to "1.1".

Nymerea commented 12 months ago

In this code

    public static Version of(final String version) {
            return switch (version) {
                case "1.0" -> V10;
                case "1.1" -> V11;
                default -> throw new IllegalArgumentException(format(
                    "Unknown version string: '%s'.", version
                ));
            };
        }

can't we make it return V11 by default ?

jenetics commented 12 months ago

Since the given GPX file is invalid, this is not my preferred fix. But I can imagine, that such files are readable with lenient mode.

final var gpx = GPX.Reader
    .of(Mode.LENIENT)
    .read("invalid.gpx");
jenetics commented 10 months ago

Merged into r3.1.0.

Nymerea commented 10 months ago

Thanks a million for the fix. I had to write my own parser with xstream. I will happilly migrate to jpx :-)