1
0
mirror of synced 2024-12-04 15:05:43 +01:00

Wait to remove elements until they are all processed

This commit is contained in:
Alex Marchant 2024-09-12 17:28:16 -04:00 committed by jvoisin
parent 1aed4ff2a5
commit d61fb7f77a

View File

@ -283,8 +283,14 @@ class MSOfficeParser(ZipParser):
for children in element.iterfind('./*'): for children in element.iterfind('./*'):
elements_ins.append((element, position, children)) elements_ins.append((element, position, children))
break break
for (element, position, children) in elements_ins: for (element, position, children) in elements_ins:
parent_map[element].insert(position, children) parent_map[element].insert(position, children)
# the list can sometimes contain duplicate elements, so don't remove
# until all children have been processed
for (element, position, children) in elements_ins:
if element in parent_map[element]:
parent_map[element].remove(element) parent_map[element].remove(element)
tree.write(full_path, xml_declaration=True, encoding='utf-8') tree.write(full_path, xml_declaration=True, encoding='utf-8')