def etree_to_dict(element, iterable=(list, list.append)):
 if ((element.text is None) or element.text.isspace()):
  retval = odict()
  for elt in element:
   if (not (elt.tag in retval)):
    retval[elt.tag] = iterable[0]()
   iterable[1](retval[elt.tag], etree_to_dict(elt, iterable))
 else:
  retval = element.text
 return retval

def etree_to_dict ( element , iterable = ( list , list . append ) ) : if ( ( element . text is None ) or element . text . isspace ( ) ) : retval = odict ( ) for elt in element : if ( not ( elt . tag in retval ) ) : retval [ elt . tag ] = iterable [ 0 ] ( ) iterable [ 1 ] ( retval [ elt . tag ] , etree_to_dict ( elt , iterable ) ) else : retval = element . text return retval
takes an xml root element and returns the corresponding dict .