0

I have been trying to locate and update certain attributes in am xml file. I am using lxml in python. I have tried the following: Assume country is an attribute of the tag address.

    frag_xml_tree = ET.parse(xml_name)
    root = frag_xml_tree.getroot()
    for elem in root.iter('address'):
                print elem.get('country')
                elem.set('country', "USA")
                print elem.get('country')

When I see the two print statements I see the update but I am not seeing the update in the actual xml file. Any help with this would be really appreciated.

I was able to figure out how to write the changes to a brand new xml but how can i edit the existing xml?

Mehrzad Chehraz
  • 5,092
  • 2
  • 17
  • 28
user4500293
  • 621
  • 1
  • 7
  • 18

0 Answers0