You need to create an instance ElementTreeand call write():
import xml.etree.ElementTree as ET
top = ET.Element('top')
child = ET.SubElement(top, 'child')
child.text = 'some text'
tree = ET.ElementTree(top)
tree.write('output.xml')
Content output.xmlafter running the code:
<top><child>some text</child></top>
source
share