Merge pull request #28 from Ede123/comments
Simplify and fix "removeComments()"
This commit is contained in:
commit
130a71327a
1 changed files with 2 additions and 11 deletions
|
|
@ -2587,20 +2587,11 @@ def removeComments(element) :
|
||||||
"""
|
"""
|
||||||
global numCommentBytes
|
global numCommentBytes
|
||||||
|
|
||||||
if isinstance(element, xml.dom.minidom.Document):
|
if isinstance(element, xml.dom.minidom.Comment):
|
||||||
# must process the document object separately, because its
|
|
||||||
# documentElement's nodes have None as their parentNode
|
|
||||||
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)
|
numCommentBytes += len(element.data)
|
||||||
element.parentNode.removeChild(element)
|
element.parentNode.removeChild(element)
|
||||||
else:
|
else:
|
||||||
for subelement in element.childNodes:
|
for subelement in element.childNodes[:]:
|
||||||
removeComments(subelement)
|
removeComments(subelement)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue