def extractText(odfElement):
 result = []
 if (len(odfElement.childNodes) != 0):
  for child in odfElement.childNodes:
   if (child.nodeType == Node.TEXT_NODE):
    result.append(child.data)
   elif (child.nodeType == Node.ELEMENT_NODE):
    subElement = child
    tagName = subElement.qname
    if (tagName == (u'urn:oasis:names:tc:opendocument:xmlns:text:1.0', u'line-break')):
     result.append('\n')
    elif (tagName == (u'urn:oasis:names:tc:opendocument:xmlns:text:1.0', u'tab')):
     result.append(' DCTB ')
    elif (tagName == (u'urn:oasis:names:tc:opendocument:xmlns:text:1.0', u's')):
     c = subElement.getAttribute('c')
     if c:
      spaceCount = int(c)
     else:
      spaceCount = 1
     result.append((' ' * spaceCount))
    else:
     result.append(extractText(subElement))
 return ''.join(result)

def extractText ( odfElement ) : result = [ ] if ( len ( odfElement . childNodes ) != 0 ) : for child in odfElement . childNodes : if ( child . nodeType == Node . TEXT_NODE ) : result . append ( child . data ) elif ( child . nodeType == Node . ELEMENT_NODE ) : subElement = child tagName = subElement . qname if ( tagName == ( u'urn:oasis:names:tc:opendocument:xmlns:text:1.0' , u'line-break' ) ) : result . append ( '\n' ) elif ( tagName == ( u'urn:oasis:names:tc:opendocument:xmlns:text:1.0' , u'tab' ) ) : result . append ( ' DCTB ' ) elif ( tagName == ( u'urn:oasis:names:tc:opendocument:xmlns:text:1.0' , u's' ) ) : c = subElement . getAttribute ( 'c' ) if c : spaceCount = int ( c ) else : spaceCount = 1 result . append ( ( ' ' * spaceCount ) ) else : result . append ( extractText ( subElement ) ) return '' . join ( result )
extract text content from an element .