#NEWLINE# def clean( document ) : #NEWLINE# #INDENT# ' Perform misc cleaning operations on documents.\n        Returns cleaned document.\n    ' #NEWLINE# newdocument = document #NEWLINE# for t in ( 't' , 'r' ) : #NEWLINE# #INDENT# rmlist = [ ] #NEWLINE# for element in newdocument . getiterator ( ) : #NEWLINE# #INDENT# if ( element . tag == ( '{%s}%s' % ( nsprefixes [ 'w' ] , t ) ) ) : #NEWLINE# #INDENT# if ( ( not element . text ) and ( not len ( element ) ) ) : #NEWLINE# #INDENT# rmlist . append ( element ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for element in rmlist : #NEWLINE# #INDENT# element . getparent ( ) . remove ( element ) #NEWLINE# #UNINDENT# #UNINDENT# return newdocument