I have a function that accepts an argument called label. This label is then used to replace the content of the element "assignedNode" using ElementTree.
The function loops through all the xml files in a directory and writes the "label" argument into the element content.
My "label" argument contains and "&" symbol but when ET writes it to the xml file it appears as "&".
Can someone instruct me how to unescape this character and force it to write the "&" symbol?
here is my code:
def apply_label(label):
clone_path = os.getcwd()
for root, dirs, files in os.walk(clone_path):
for f in files:
try:
tree = ET.ElementTree(file=f)
root = tree.getroot()
for assignedNode in root.iter("assignedNode"):
assignedNode.text = label
tree = ET.ElementTree(root)
with open(f, "w") as a:
tree.write(a)
except :
pass