def gatherTextNodes(iNode, dounescape=0, joinWith=''):
 gathered = []
 gathered_append = gathered.append
 slice = [iNode]
 while (len(slice) > 0):
  c = slice.pop(0)
  if (hasattr(c, 'nodeValue') and (c.nodeValue is not None)):
   if dounescape:
    val = unescape(c.nodeValue)
   else:
    val = c.nodeValue
   gathered_append(val)
  slice[:0] = c.childNodes
 return joinWith.join(gathered)

def gatherTextNodes ( iNode , dounescape = 0 , joinWith = '' ) : gathered = [ ] gathered_append = gathered . append slice = [ iNode ] while ( len ( slice ) > 0 ) : c = slice . pop ( 0 ) if ( hasattr ( c , 'nodeValue' ) and ( c . nodeValue is not None ) ) : if dounescape : val = unescape ( c . nodeValue ) else : val = c . nodeValue gathered_append ( val ) slice [ : 0 ] = c . childNodes return joinWith . join ( gathered )
visit each child node and collect its text data .