def dict_to_etree(d, parent):
 for (k, v) in d.items():
  if (v is None):
   etree.SubElement(parent, k)
  elif isinstance(v, six.string_types):
   etree.SubElement(parent, k).text = v
  elif (isinstance(v, dict) or isinstance(v, odict)):
   child = etree.SubElement(parent, k)
   dict_to_etree(v, child)
  elif (not isinstance(v, collections.Sized)):
   etree.SubElement(parent, k).text = str(v)
  elif (len(v) == 0):
   etree.SubElement(parent, k)
  else:
   for e in v:
    child = etree.SubElement(parent, k)
    if (isinstance(e, dict) or isinstance(e, odict)):
     dict_to_etree(e, child)
    else:
     child.text = str(e)

def dict_to_etree ( d , parent ) : for ( k , v ) in d . items ( ) : if ( v is None ) : etree . SubElement ( parent , k ) elif isinstance ( v , six . string_types ) : etree . SubElement ( parent , k ) . text = v elif ( isinstance ( v , dict ) or isinstance ( v , odict ) ) : child = etree . SubElement ( parent , k ) dict_to_etree ( v , child ) elif ( not isinstance ( v , collections . Sized ) ) : etree . SubElement ( parent , k ) . text = str ( v ) elif ( len ( v ) == 0 ) : etree . SubElement ( parent , k ) else : for e in v : child = etree . SubElement ( parent , k ) if ( isinstance ( e , dict ) or isinstance ( e , odict ) ) : dict_to_etree ( e , child ) else : child . text = str ( e )
takes a the dict whose value is either none or an instance of dict .