Thanks Larz60+ & Snippsat. I'm able to pass through and new file is being generated with below code but this is deleting the comments which are already there in source xml file. Any thoughts on how to get the comments as well to the new file ?
import xml.etree.ElementTree as ET def newidentity(filename): tree = ET.ElementTree(file=filename) root = tree.getroot() for id in root.iter('identity'): print id.text identity.text = "123456" tree = ET.ElementTree(root) print tree with open("newfile.xml", "wb") as somefile: tree.write(somefile) if __name__ == "__main__": newidentity(filename)