Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xml.dom import minidom
- import xml.etree.cElementTree as ET
- root = ET.Element("root")
- doc = ET.SubElement(root, "doc")
- field1 = ET.SubElement(doc, "field1")
- field1.set("name", "blah")
- field1.text = "some value1"
- field2 = ET.SubElement(doc, "field2")
- field2.set("name", "asdfasd")
- field2.text = "some vlaue2"
- dom = minidom.parseString(ET.tostring(root))
- print dom.toprettyxml(indent='t')
- <?xml version="1.0" ?>
- <root>
- <doc>
- <field1 name="blah">some value1</field1>
- <field2 name="asdfasd">some vlaue2</field2>
- </doc>
- </root>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement