Question

I am retrieving all the coords from a gpx file, and here is a sample line from that file

 <gpxx:rpt lon="11.0739613" lat="47.5691700"/>

In IE and FireFox, the following code executes correctly:

var routePoints = data.documentElement.getElementsByTagName("gpxx:rpt");

for (var i = 0; i < routePoints.length; i++) 
 {
     routePoints[i].getAttribute("lat");
     routePoints[i].getAttribute("lon");
 }

Although strangely, on Chrome this code does not work, it does not seem to retrieve any info from the DOM.

On my travels for a solution I've seen 'getElementsByTagNameNS(ns,name)' but looking at the example on http://www.w3schools.com/dom/met_element_getelementsbytagnamens.asp I haven't managed to ascertain if that is in fact of any help to me.

Any tips appreciated

Many Thanks

David

Était-ce utile?

La solution

Yes, your file is using namespaces, so you should use the namespace-aware version of this method.

  • If you know the namespace of your gpxx: prefix, then use:

    getElementsByTagNameNS(your_namespace, "rpt")

  • If your file doesn't use any other namespaces with rpt elements, then this should be enough:

    getElementsByTagNameNS("*", "rpt")

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top