Remove empty defs, metadata, g elements

This commit is contained in:
JSCHILL1 2009-04-06 19:37:58 -05:00
parent 6cb18b63ed
commit 18d6566520

View file

@ -300,6 +300,23 @@ while bContinueLooping:
numStylePropsFixed = repairStyle(doc.documentElement) numStylePropsFixed = repairStyle(doc.documentElement)
# remove empty defs, metadata, g
# NOTE: these elements will be removed even if they have (invalid) text nodes
elemsToRemove = []
for tag in ['defs', 'metadata', 'g'] :
for elem in doc.documentElement.getElementsByTagNameNS(NS['SVG'], tag) :
removeElem = not elem.hasChildNodes()
if removeElem == False :
for child in elem.childNodes :
print child.nodeType,
if child.nodeType in [1, 4, 8] :
break
else:
removeElem = True
if removeElem :
elem.parentNode.removeChild(elem)
numElemsRemoved += 1
# output the document # output the document
doc.documentElement.writexml(output) doc.documentElement.writexml(output)