forked from driscollis/python101code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_xml.py
More file actions
18 lines (12 loc) · 427 Bytes
/
edit_xml.py
File metadata and controls
18 lines (12 loc) · 427 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# edit_xml.py
import xml.etree.cElementTree as ET
def edit_xml(xml_file, output_file, from_person):
tree = ET.ElementTree(file=xml_file)
root = tree.getroot()
for from_element in tree.iter(tag='from'):
from_element.text = from_person
tree = ET.ElementTree(root)
with open(output_file, "wb") as f:
tree.write(f)
if __name__ == '__main__':
edit_xml('note.xml', 'output.xml', 'Guido')