def itertext(elem):
 if elem.text:
  (yield elem.text)
 for e in elem:
  for s in itertext(e):
   (yield s)
  if e.tail:
   (yield e.tail)

def itertext ( elem ) : if elem . text : ( yield elem . text ) for e in elem : for s in itertext ( e ) : ( yield s ) if e . tail : ( yield e . tail )
loop through all children and return text only .