XML parsing and writing

Stefan Behnel stefan.behnel-n05pAM at web.de
Tue Aug 29 03:03:34 EDT 2006


c00i90wn wrote:
> Stefan Behnel wrote:
>> c00i90wn wrote:
>>> Hey, I'm having a problem with the xml.dom.minidom package, I want to
>>> generate a simple xml for storing configuration variables, for that
>>> purpose I've written the following code, but before pasting it I'll
>>> tell you what my problem is. On first write of the xml everything goes
>>> as it should but on subsequent writes it starts to add more and more
>>> unneeded newlines to it making it hard to read and ugly.
>> Maybe you should try to get your code a little cleaner first, that usually
>> helps in finding these kinds of bugs. Try rewriting it with ElementTree or
>> lxml, that usually helps you in getting your work done.
>>
>> http://effbot.org/zone/element-index.htm
>> http://codespeak.net/lxml/
>
> Nice package ElementTree is but sadly it doesn't have a pretty print,
> well, guess I'll have to do it myself, if you have one already can you
> please give it to me? thanks :)

lxml's output functions all accept a "pretty_print" keyword argument.

Stefan



More information about the Python-list mailing list