-
-
Save zeffii/8300729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.sax.saxutils import XMLGenerator | |
import StringIO | |
import xml.dom.minidom | |
# unformatted | |
with open("dragons.xml", "w") as outfile: | |
w = XMLGenerator(outfile, 'utf-8') | |
w.startDocument() | |
w.startElement("test", {'bar': 'baz'}) | |
w.characters("Foo") | |
w.endElement("test") | |
w.endDocument() | |
# formatted | |
with open("dragons.xml") as infile: | |
w = infile.read() | |
dom = xml.dom.minidom.parseString(w) | |
k = dom.toprettyxml() | |
print(k) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment