danielperezunlpam

ElementTree

Nov 26th, 2020
553
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import xml.etree.ElementTree as et
  2.  
  3. if __name__ == '__main__':
  4.     tree = et.parse("xml_folder/country.xml")
  5.     print(type(tree))
  6.     print(tree)
  7.     root = tree.getroot()
  8.     print(type(root))
  9.     print(root)
  10.  
  11.     for child in root:
  12.         child.text = child.text.upper()
  13.  
  14.         child.attrib["iso"] = "45"
  15.         print(child.text, child.attrib)
  16.  
  17.  
  18.     tree.write("xml_folder/country_2.xml")
RAW Paste Data