Failing “find” when parsing GPX XML with jQuery

When using jQuery for parsing GPX data (which is an XML format) you may experience a weird problem of being unable to access extra elements (nodes) added by software used to process the data, such as QGIS.

A typical example would be having such data in the file and being able to read “extensions” as an abject, being able to access its contents as text, but mysteriously failing when attempting to read “ogr:id”, which was added by QGIS:

<extensions>
<ogr:id>1</ogr:id>
</extensions>

The good news is that it is not your fault. Actually the culprit is jQuery itself, which fails to operate correctly with the node identifiers from different namespace due to a bug.

The easiest solution is to escape the colon with two backslashes, like this:

var mytest = $(this).find(‘extensions’).find(“ogr\\:id”).text();

Read more about it here.