I have a requirement where I have a sample XML file with a well defined structure. I want to search of a tag/child in XML file, replace its text/value with some input file and save the changes to a new XML file preferably without effecting the input sample XML.
I understand this can be achieved by a XML parser to traverse through to the child as intended. But problem is that at the top of my XML file I have something like this
<nc:data xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
I have written a python function as shown below to do it but I am failing to get the intended thing.
def search_replace():
replicate() // This function just makes a tmp file from sample input XML to work on.
tree = et.parse("/path/to/file/tmp_file.xml")
tree.find('nc:data/child1/child2/child3').text = 'test'
tree.write("new_file.xml")
Please suggest what would be best approach to handle this. I am not very python-skilled as of now !!