I am parsing an XML file and I need to populate a nested dictionary where keys of inner dictionary points a list object. I need to append a new value to the inner list at every iteration.
Sample XML
<entry name = 'Europe'>
<entry name = 'Spain'>
<from>'Madrid'</from>
<from>'Barcelona'</from>
<entry name = 'Nederland'>
<from>'Amsterdam'</from>
<from>'Roterdam'</from>
I need to have such output from parsing
d = {'Europe':{'Spain':['Madrid','Barcelona']}, {'Nederland':['Amsterdam','Roterdam']}
I am using xml.etree.ElementTree to parse XML. However, couldn't populate such a dictionary above. The code I did
import xml.etree.ElementTree as ET
tree = ET.parse(europe.xml)
root = tree.getroot()
for i in root.findall('.//entry'):
for j in root.findall(''.//entry/):
l = []
l_new = [:]
for k in root.findall('.//entry/entry/):
l_new.append(k.text)
d1[j] = l_new
...
Any idea?