I would like to modify the xml file as below using xml.etree.ElementTree.
<?xml version="1.0" encoding="UTF-8"?>
<FAMILY
CATEGORY = "Old Category"
NAME = "Old Name"
>
By the way,
import xml.etree.ElementTree import parse
xml = parse(file)
root = xml.getroot()
category = root.get('CATEGORY')
name = root.get('NAME')
category = "New Category"
name = "New Name"
xml.write(file)
The indentation and string changes that I used in the beginning are all gone In the first line again, this part is also flying away... Is there a better way to modify the xml file in Python?
python xml
xml.write(file, encoding="utf-8", xml_declaration=True)
© 2024 OneMinuteCode. All rights reserved.