Skip to content

Commit

Permalink
Fixed issue with correctly updating loaded data
Browse files Browse the repository at this point in the history
  • Loading branch information
sevisal committed Sep 19, 2023
1 parent aedc426 commit 16774eb
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions src/vai_lab/Data/xml_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,11 @@ def load_XML(self, filename: str) -> None:
self.set_filename(filename)
if hasattr(self, 'tree'):
prev_tree = self.tree
self.tree = self._combine_Initialiser(ET.parse(self.filename).getroot(), prev_tree.getroot(), False)
self.tree = self._combine_XML(prev_tree.getroot(), ET.parse(self.filename).getroot())
else:
self.tree = ET.parse(self.filename)
self._parse_XML()

def _combine_Initialiser(self, tree1, tree2, module = True):

# Create a mapping from tag name to element, as that's what we are fltering with
mapping = {el.tag: el for el in tree1}
for el in tree2:
if el.tag == 'Initialiser' or module:
if len(el) == 0:
# Not nested
try:
# Update the text
mapping[el.tag].text = el.text
except KeyError:
# An element with this name is not in the mapping
mapping[el.tag] = el
# Add it
tree1.append(el)
else:
try:
# Recursively process the element, and update it in the same way
self._combine_XML(mapping[el.tag], el)
except KeyError:
# Not in the mapping
mapping[el.tag] = el
tree1.append(el)
return ET.ElementTree(tree1)

def _combine_XML(self, tree1, tree2):
"""
This function recursively updates either the text or the children
Expand Down

0 comments on commit 16774eb

Please sign in to comment.