ElementTree write creates large one line XML file ....
Robert Kern
robert.kern at gmail.com
Thu May 27 20:13:02 EDT 2010
On 5/27/10 7:52 PM, robert somerville wrote:
> Hi I am using Ubuntu 9.10 and Python 2.6.4 ..
>
> when I create an ElementTree object and the write it out using:
>
> xml.etree.ElementTree.write() , I get one single long single line
> files, instead of something that looks reasonable , what gives ??? (and
> is it important ??)
ElementTree writes exactly what you tell it to. In XML, whitespace is
significant. If you want newlines and/or indentation to make it pretty-looking,
then you need to add those to your elements.
Fredrik provides an example function for doing this:
http://effbot.org/zone/element-lib.htm#prettyprint
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list