1import xml.etree.cElementTree as ET
2
3root = ET.Element("root")
4doc = ET.SubElement(root, "doc")
5
6ET.SubElement(doc, "field1", name="blah").text = "some value1"
7ET.SubElement(doc, "field2", name="asdfasd").text = "some vlaue2"
8
9tree = ET.ElementTree(root)
10tree.write("filename.xml")
11
1#code :
2import xml.etree.cElementTree as ET
3
4root = ET.Element("root")
5doc = ET.SubElement(root, "doc")
6
7ET.SubElement(doc, "field1", name="blah").text = "some value1"
8ET.SubElement(doc, "field2", name="asdfasd").text = "some vlaue2"
9
10tree = ET.ElementTree(root)
11tree.write("filename.xml")
12
13#output : filename.xml ->
14"""
15<root>
16 <doc>
17 <field1 name="blah">some value1</field1>
18 <field2 name="asdfasd">some vlaue2</field2>
19 </doc>
20</root>
21""""