Reputation: 16825
I have the following XML (it's actually a gpx file)
<?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>
I load it via:
var parser = new DOMParser();
xmlDocument = parser.parseFromString(xml, 'application/xml');
This works:
xml.getElementsByTagName('gpx')
>[gpx]
But this does not
xml.getElementsByTagName('gpxdata:distance')
>[]
Although I see that its tag name is gpxdata:distance
in the chromewebtools.
The Standart says:
The getElementsByTagName(qualifiedName) method, when invoked, must return the list of elements with qualified name qualifiedName for context object.
What am I missing?
Upvotes: 0
Views: 264
Reputation: 943537
gpxdata:distance
is not a tag name.
gpxdata
is a namespace. distance
is a tag name.
xml.getElementsByTagNameNS(
"http://www.garmin.com/xmlschemas/TrackPointExtension/v1",
"distance"
);
Upvotes: 1