Apr-05-2021, 11:53 PM
(This post was last modified: Apr-05-2021, 11:53 PM by ateestructural.)
I have this code but the text is not replaced in the file titled: file_name (although as a python string the replacement is correct but I expected to change in file_name)
Can anyone figure why is that?
Can anyone figure why is that?
def xml_parsing(file_name, append_values, search_1, search_2): from xml.etree import ElementTree with open(file_name, 'rb+') as f: tree = ElementTree.parse(f) root = tree.getroot() root.find(search_1).text.replace("(VALUE)DS-L462-060901-C01-21(/VALUE)", "(VALUE)" + str(append_values[0]) + "(/VALUE)") tree.write(file_name, xml_declaration=True, encoding='utf-8')