from itertools import chain from lxml import etree def stringify_children(node): ''' Return all contents of an xml tree, without the outside tags. e.g. if node is parse of "Hi
there Bruce!
" should return "Hi
there Bruce!
" fixed from http://stackoverflow.com/questions/4624062/get-all-text-inside-a-tag-in-lxml ''' parts = ([node.text] + list(chain(*([etree.tostring(c), c.tail] for c in node.getchildren()) ))) # filter removes possible Nones in texts and tails return ''.join(filter(None, parts))