Garmin GPX Extension Validation

I can't find a good Garmin forum for my question; however, this one appears to be the most relevant.

https://www8.garmin.com/support/download_details.jsp?id=927
POI Loader for Windows allows you to load custom points of interest into your unit. The input files can be downloaded from the internet or you can create your own.

I have I website (https://gpx-poi.com/) that can be used to create GPX input files. Where can I find documentation that will allow me to perform a schema validation of these files?

This is the only documentation I can find regarding the schema reference and several of the Garmin URLs in that sample do not even resolve:
https://en.wikipedia.org/wiki/GPS_Exchange_Format#Sample_GPX_document

The first line of the Garmin XSD file has a URL that does not resolve:
https://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd

<xsd:schema targetNamespace="">www.garmin.com/.../v3" elementFormDefault="qualified">

This is a link to the Topografix documentation. I can't find the equivalent Garmin extension documentation:
http://www.topografix.com/GPX/1/1/

Basic GPX file validation:

$ cat v1sample.gpx
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="www.topografix.com/.../1 ">www.topografix.com/.../gpx.xsd"
version="1.1"
creator="gpx-poi.com">

<wpt lat="17.000000" lon="0.000000">
<time>2021-02-27T23:15:59Z</time>
</wpt>
</gpx>

$ xmllint --noout --schema http://www.topografix.com/GPX/1/1/gpx.xsd v1sample.gpx
v1sample.gpx validates

GPX file with Garmin extension (www.garmin ==> www8.garmin for some URLs to resolve):

$ cat v3sample.gpx
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gpx
  xmlns="">www.topografix.com/.../1"
  xmlns:gpxx="">www8.garmin.com/.../v3"
  xmlns:xsi="">www.w3.org/.../XMLSchema-instance"
  xsi:schemaLocation="www.topografix.com/.../1 www.topografix.com/.../gpx.xsd
  www8.garmin.com/.../v3
  ">www8.garmin.com/.../GpxExtensionsv3.xsd"
  version="1.1"
  creator="gpx-poi.com">
  <wpt lat="17.000000" lon="0.000000">
    <time>2021-02-28T00:04:17Z</time>
    <extensions>
      <gpxx:WaypointExtension>
        <gpxx:Proximity>1000</gpxx:Proximity>
      </gpxx:WaypointExtension>
    </extensions>
  </wpt>
</gpx>

$ xmllint --noout --schema www8.garmin.com/.../GpxExtensionsv3.xsd v3sample.gpx
warning: failed to load external entity "">www8.garmin.com/.../GpxExtensionsv3.xsd"
Schemas parser error : Failed to locate the main schema resource at 'www8.garmin.com/.../GpxExtensionsv3.xsd'.
WXS schema www8.garmin.com/.../GpxExtensionsv3.xsd failed to compile

  • FWIW, I have been working with GPX files for many years (15+), and I have never, ever, made use schemas. I have always worked with simple GPX elements and used <extensions> for my own purpose.

    The whole world (namespace??) of schemas has remained entirely foreign to me, and I have never suffered.

  • It depends on the use case. The users of my web service (https://gpx-poi.com/) have asked for the ability to upload GPX files.For that to function reliably I would need to validate the file.

  • TL;DR

    I was able to get this working with xmllint by:

    - Downloading the GPX, GpxExtensionsv3 and TrackPointExtensionsv1 XSDs and defining a wrapper schema to load all of them (because xmllint won't load https links and also won't load multiple schemas from the command line)

    - Editing the GPX and GpxExtensionsv3 XSDs to change the latitudeType / longitudeType definitions from xsd:decimal to xsd:string, because xmllint doesn't like more than 18 decimals


    I'm able to open the XSD file in a browser (Chrome or Firefox):

    https:// www8 .garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3 .xsd

    (I split the URL up because the forum freaks out when you link to an XML file...)

    But it doesn't work in xmllint (on WSL Ubuntu) -- I get the same error as you. I think the reason is that xmllint doesn't work with https urls.

    If I download the file and reference it locally, then I get the following error when validating against an exported activity GPX:

    [test.gpx:6: element gpx: Schemas validity error : Element '{http://www.topografix.com/GPX/1/1}gpx': No matching global declaration available for the validation root.]
    
    

    Looking at xsi:schemaLocation in the exported GPX, the URL is incorrect:

    xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/11.xsd"

    The correct URL is: http :// www .topografix.com/GPX/1/1/gpx.xsd

    Even after fixing the URL, it doesn't work, because xmllint apparently doesn't open XSD files referenced in xsi:schemaLocation.

    So I downloaded gpx.xsd and created a wrapper schema. I also had to download the trackpoint extension v1 xsd (otherwise trackpoint extensions won't be validated -- invalid data will be ignored silently): https:// www8. garmin.com/xmlschemas/TrackPointExtensionv1 .xsd

    gpxwrapper.xsd:

    <?xml version="1.0" encoding="UTF-8"?>
    <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema">
        <import namespace="http://www.topografix.com/GPX/1/1" schemaLocation="gpx.xsd"/>
        <import namespace="http://www.garmin.com/xmlschemas/GpxExtensions/v3" schemaLocation="GpxExtensionsv3.xsd"/>
        <import namespace="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" schemaLocation="TrackPointExtensionv1.xsd"/>
    </schema>

    I used this command line to validate:

    xmllint --noout --schema gpxwrapper.xsd  test.gpx

    Unfortunately, validation still fails because the trackpoint lat/lon attributes have 29 decimals in my exported activity GPX, but xmllint only supports 18 apparently.

    https://stackoverflow.com/questions/26301369/is-this-really-not-a-valid-xsdecimal

    So I changed the definition of latitudeType and longitudeType in both the Garmin GPX xsd (GpxExtensionsv3.xsd) and the Topographix xsd (gpx.xsd) to be xsd:string.

    Finally my GPX file validates. As a sanity check, I changed some elements/attributes in the test GPX to be invalid, and the file fails to validate, as expected

    I suggest finding a better xml linter tho.

  • (Note that links to XML files seem to be broken in these forums. If you manage to post a link to an XML file, it seems that the forum wants to render the XML instead of showing you a link.

    I hate these forums so much.)

  • I recently migrated from PHP to Go. Wink

    My site only supports the waypoint extension, while the repository you are pointing to only supports trackpoints.

    If you click on the Garmin link that the repository references you will get a 404 Not Found status. This is the behavior I have also observed. Garmin sites that used to have valid content are now gone.

  • Check out my comment below for a working solution with xmllint.

    forums.garmin.com/.../1250113