How to parse a list of waypoints using python and xml.etree? -


the following list of points represent track

   <track_vertices>         <point1>36 35.58 n, 1 8.91 w</point1>         <point2>36 42.56 n, 0 56.27 w</point2>         <point3>36 40.91 n, 0 54.86 w</point3>         <point4>36 33.94 n, 1 7.5 w</point4>         <point5>36 32.29 n, 1 6.09 w</point5>         <point6>36 39.27 n, 0 53.45 w</point6>         <point7>36 37.62 n, 0 52.04 w</point7>         <point8>36 30.64 n, 1 4.68 w</point8>         <point9>36 28.99 n, 1 3.27 w</point9>         <point10>36 35.97 n, 0 50.63 w</point10> 

every track has diferent number of waypoints.

the waypoint position parsed follows.

root.find("*sru_track_vertices/point1") 

buy don´t know number after "pointx", them trying

root.findall("*sru_track_vertices/point*") 

how can not using regex ?

simply invoke .text - can output waypoints this:

track = root.find('.//track_vertices')  in range(1, len(track)+1):     waypoint = track.find('point{}'.format(i)).text      print(waypoint) 

for <track_vertices> elements:

tracks = root.findall('.//track_vertices')  t in tracks:      in range(1, len(t)+1):         waypoint = t.find('point{}'.format(i)).text          print(waypoint) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -