Note that there are some explanatory texts on larger screens.

plurals
  1. POpython xml extraction for loop
    text
    copied!<p>I have a bit of script that I think is nearly there. I have worked out a crude way of writing it, but I can't work out how to get it to function as a for loop.</p> <p>I am extracting data from an xml file that uses the following format:</p> <pre><code>&lt;Trackpoint&gt; &lt;Time&gt;2012-01-17T11:44:35Z&lt;/Time&gt; &lt;Position&gt; &lt;LatitudeDegrees&gt;51.920211518183351&lt;/LatitudeDegrees&gt; &lt;LongitudeDegrees&gt;26.706042898818851&lt;/LongitudeDegrees&gt; &lt;/Position&gt; &lt;AltitudeMeters&gt;-43.6026611328125&lt;/AltitudeMeters&gt; &lt;/Trackpoint&gt; &lt;Trackpoint&gt; &lt;Time&gt;2012-01-17T11:45:21Z&lt;/Time&gt; &lt;Position&gt; &lt;LatitudeDegrees&gt;51.920243117958307&lt;/LatitudeDegrees&gt; &lt;LongitudeDegrees&gt;26.706140967085958&lt;/LongitudeDegrees&gt; &lt;/Position&gt; &lt;AltitudeMeters&gt;-43.6026611328125&lt;/AltitudeMeters&gt; &lt;/Trackpoint&gt; </code></pre> <p>I can use the following to get say the LatitudeDegrees:</p> <pre><code>from xml.dom.minidom import parse doc = parse('/Users/name/Documents/GPS/gps.tcx') lat = doc.getElementsByTagName("LatitudeDegrees") time = doc.getElementsByTagName("Time") trackpoint = doc.getElementsByTagName("Trackpoint") for x in lat: print(x.firstChild.data) </code></pre> <p>but I would like to get the Lat, Long and time in order.</p> <p>I am guessing I need to use </p> <pre><code>for x in trackpoint </code></pre> <p>but the only way I can work out how to do that is as follows. </p> <pre><code>count = 0 n = len(trackpoint) while count &lt; n: print(time[count].firstChild.data) print(lat[count].firstChild.data) print(lon[count].firstChild.data) count += 1 </code></pre> <p>anyone have any ideas? I think I am just missing something really simple!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload