def xml_to_string(elem, pretty=False):
 if pretty:
  elem = pretty_print_xml(elem)
 try:
  return ElementTree.tostring(elem)
 except TypeError as e:
  if hasattr(elem, 'text'):
   return ('<!-- %s -->\n' % elem.text)
  else:
   raise e

def xml_to_string ( elem , pretty = False ) : if pretty : elem = pretty_print_xml ( elem ) try : return ElementTree . tostring ( elem ) except TypeError as e : if hasattr ( elem , 'text' ) : return ( '<!-- %s -->\n' % elem . text ) else : raise e
returns a string from an xml tree .