[Tutor] Reformatting a one (long) line xml file
Christopher Arndt
chris.arndt at web.de
Wed Sep 28 19:19:07 CEST 2005
Negroup - schrieb:
> Hi all, I have an xml file where the tags are all on the same line,
> without any newline. This file is quite big and difficult to read. I'd
> like to format it in a convenient way, using indentation and nesting.
> How to pretty print my content?
Untested:
import sys
from xml.dom import minidom
file = sys.argv[1]
doc = minidom.parse(file)
print doc.toprettyxml(indent=2)
See http://www.python.org/doc/current/lib/module-xml.dom.minidom.html for more
info.
HTH, Chris
More information about the Tutor
mailing list