I'm working in JavaScript with XML-code and working to create a heatmap, XML looks like this :
<> pre & lt; TRK & gt; & Lt; Name & gt; Oscars & lt; / Name & gt; & Lt; Trkseg & gt; & Lt; Trkpt lat = "20.922436" lawn = "- 32.950274" & gt; & Lt; Elephant & gt; 35.23 & lt; / Elephant & gt; & Lt; Time & gt; 2013-04-28T09: 23: 11z & lt; / Time & gt; & Lt; / Trkpt> & Lt; Trkpt lat = "21.231232" law = "- 30.9123123" & gt; & Lt; Elephant & gt; 35.23 & lt; / Elephant & gt; & Lt; Time & gt; 2013-04-28T09: 23: 11z & lt; / Time & gt; & Lt; / Trkpt> & Lt; / Trkseg & gt; & Lt; / TRK & gt;
But I think that "trkpt" does not seem to be able to target because it has lat = and lon = value, which is always different. How can I target that header? I have tried to use this:
getElementsByTagName ("trkpt")
but can not get this information - what do I remember here Am I
Thanks for the help
UPDATE
A code snippet that says what I've tried so far:
var xmlParsing = new XMLHttpRequest); Var xmlDoc = "Hello"; Var readyString = "asd"; XmlParsing.open ("GET", "3.xml", Incorrect); XmlParsing.send (); XmlDoc = xmlParsing.responseXML; Var x = xmlDoc.getElementsByTagName ("trk"); Var y = xmlDoc.getElementsByTagName ("trkseg"); (I = 0; i & lt; x.length; i ++) {document.write (x [i] .getElementsByTagName ("name") [0] .childNodes [0] .nodeValue); Document.write (": & lt; em>;); (E = 0; e & lt; y.length; e ++) {document.write (y [E] .getElementsByTagName ("trkpt") [0] .childNodes [0] .nodeValue); } Document.write ("& lt; / em> "); }
To see what I am doing, just look at the values and print most of it.
The result returns this:
Academy
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
The problem is as follows:
y [E] .getElementsByTagName (" trkpt ") [0]. ChildNode [0]. NodeValue
The childNodes
of this element is not what you expect if you do:
console.log ( Y [E] .getElementsByTagName ("trkpt") [0]. ChildNodes);
Then you will see the following:
[text, ele, text, time, text]
Nodes have to be filtered You can try to use:
y [E] .getElementsByTagName ("trkpt") [0] .firstElementChild.textContent
But if you want other nodes, then you should loop and filter the text nodes:
var children = y [e] .getElementsByTagName ("trkpt") [0] ] .childNodes; For (var c = 0; c & lt; children.length; c ++) {if (children [c] .nodeType == node. ELEMENT_NODE) {// whatever can be console.log (children [c] ] .textContent); }}
Comments
Post a Comment