def etree_to_dict(t):
    d = {t.tag: map(etree_to_dict, t.iterchildren())}
d.update(('@' + k, v) for k, v in t.attrib.items())
d['text'] = t.text
return d
Converting xml to dictionary using ElementTree