def remove_ignorable_whitespace(node):
 if (node.tail and (node.tail.strip() == '')):
  node.tail = None
 for child in node:
  if (node.text and (node.text.strip() == '')):
   node.text = None
  remove_ignorable_whitespace(child)

def remove_ignorable_whitespace ( node ) : if ( node . tail and ( node . tail . strip ( ) == '' ) ) : node . tail = None for child in node : if ( node . text and ( node . text . strip ( ) == '' ) ) : node . text = None remove_ignorable_whitespace ( child )
remove insignificant whitespace from xml nodes it should only remove whitespace in between elements and sub elements .