def removeComments(element):
 global numCommentBytes
 if isinstance(element, xml.dom.minidom.Document):
  for subelement in element.childNodes:
   if isinstance(element, xml.dom.minidom.Comment):
    numCommentBytes += len(element.data)
    element.documentElement.removeChild(subelement)
   else:
    removeComments(subelement)
 elif isinstance(element, xml.dom.minidom.Comment):
  numCommentBytes += len(element.data)
  element.parentNode.removeChild(element)
 else:
  for subelement in element.childNodes:
   removeComments(subelement)

def removeComments ( element ) : global numCommentBytes if isinstance ( element , xml . dom . minidom . Document ) : for subelement in element . childNodes : if isinstance ( element , xml . dom . minidom . Comment ) : numCommentBytes += len ( element . data ) element . documentElement . removeChild ( subelement ) else : removeComments ( subelement ) elif isinstance ( element , xml . dom . minidom . Comment ) : numCommentBytes += len ( element . data ) element . parentNode . removeChild ( element ) else : for subelement in element . childNodes : removeComments ( subelement )
removes comments from the element and its children .