I am trying to get information in an XML file. I am trying to do that with ElementTree, however it seems that what I am currently doing breaks the xml structure in python.
Here there is the XML:
<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase>
<Activities>
<Activity>
<Id>2018-05-23</Id>
<Lap>
<TotalTimeSeconds>19204.0</TotalTimeSeconds>
<MaximumHeartRateBpm>
<Value>137</Value>
</MaximumHeartRateBpm>
<Track>
<Trackpoint>
<Time>2018-05-23</Time>
<HeartRateBpm>
<Value>79</Value>
</HeartRateBpm>
<SensorState>Present</SensorState>
</Trackpoint>
<Trackpoint>
<Time>2018-05-23</Time>
<HeartRateBpm>
<Value>80</Value>
</HeartRateBpm>
<SensorState>Present</SensorState>
</Trackpoint>
</Track>
</Lap>
</Activity>
</Activities>
</TrainingCenterDatabase>
My really simple code is the following:
e = ET.parse('fileName.xml').getroot()
e = e.find('./Activities/Activity/Lap/Track')
print(e)
This code returns the following error:
AttributeError: 'NoneType' object has no attribute 'iter'
I have followed the documentation and some question on stack, as 1. My final output would be some variables that contain the one time information as: MaximumHeartRateBpm, TotalTimeSeconds and Id. Moreover I would like to get a list of dictionaries for the Track item with the following structure:
[{"Time": val, "HeartRateBpm": val, "SensorState": val},
...,
{"Time": val, "HeartRateBpm": val, "SensorState": val}]
I cannot attempt the second one as I am not able to look into the xml.
Thank you.