(Apr-21-2017, 01:26 PM)kendias Wrote: My question is - I want to use these readings to control a robot, do I have to convert this into another format and do the calcs or can I use as is.Use a parer for XML data eg BeautifulSoup.
Here a demo,i insert regex to
find all()
to get all numbered Accelerometer1 2 3
Then loop over and convert to
float()
from bs4 import BeautifulSoup import re xml ='''\ <Node Id>node12</Node Id> <GPS> <Latitude>1.123123</Latitude> <Longitude>234.1231231</Longitude> <Accuracy>40.0</Accuracy> </GPS> <Accelerometer> <Accelerometer1>0.38444442222</Accelerometer1> <Accelerometer2>0.03799999939</Accelerometer2> <Accelerometer3>9.19400000331</Accelerometer3> </Accelerometer> <TimeStamp>1370354489083</TimeStamp>''' soup = BeautifulSoup(xml, 'html.parser') acc_meter = soup.find_all(re.compile("meter\d")) for value in acc_meter: print(float(value.text))
Output:0.38444442222
0.03799999939
9.19400000331