Javascript getElementsByTagName 未返回结果

Javascript getElementsByTagName not returning results

我有以下XML(实际上是一个gpx文件)

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<gpx version="1.1" creator="Movescount - http://www.movescount.com" 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.cluetrust.com/XML/GPXDATA/1/0 http://www.cluetrust.com/Schemas/gpxdata10.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns="http://www.topografix.com/GPX/1/1">
  <trk>
    <name>Move</name>
    <trkseg>
      <trkpt lat="52.3535" lon="4.848642">
        <ele>12</ele>
        <time>2017-05-05T06:25:41.000Z</time>
        <extensions>
          <gpxtpx:TrackPointExtension xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1">
            <gpxtpx:hr>105</gpxtpx:hr>
          </gpxtpx:TrackPointExtension>
          <gpxdata:cadence>81</gpxdata:cadence>
          <gpxdata:temp>22.7000007629395</gpxdata:temp>
          <gpxdata:distance>-19.1377588523053</gpxdata:distance>
          <gpxdata:altitude>12</gpxdata:altitude>
          <gpxdata:seaLevelPressure>1024</gpxdata:seaLevelPressure>
          <gpxdata:speed>3.20000004768372</gpxdata:speed>
          <gpxdata:verticalSpeed>0</gpxdata:verticalSpeed>
        </extensions>
      </trkpt>
    </trkseg>
  </trk>
</gpx>

我通过以下方式加载它:

var parser = new DOMParser();
xmlDocument = parser.parseFromString(xml, 'application/xml');

这个有效:

xml.getElementsByTagName('gpx')
>[gpx]

但这并不

xml.getElementsByTagName('gpxdata:distance')
>[]

虽然我在chromewebtools中看到它的标签名称是gpxdata:distance

Standart 说:

The getElementsByTagName(qualifiedName) method, when invoked, must return the list of elements with qualified name qualifiedName for context object.

我错过了什么?

gpxdata:distance 不是标签名称。

gpxdata 是一个命名空间。 distance 是标签名称。

xml.getElementsByTagNameNS(
    "http://www.garmin.com/xmlschemas/TrackPointExtension/v1",
    "distance"
);