470,591 Members | 1,585 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

XML minidom Parsing and ToPrettyXML

I am trying to write a script that reads an XML file (using the
minidom module), makes an edit to a few attributes, then saves it
back. If I use minidom.Document() to create the xml file, then write
it with toprettyprint, it looks fine.

However, if I use xml.minidom.parse to parse the xml document, change
a few attributes with setAttribute, then write back with toprettyxml,
my XML file gets loaded up with spaces between many of the elements.

Like this,
<?xml ... ?>
<root>

<tile />

<tile />

<tile />
</root>

I assume this has to do with the way xml.dom.minidom.parse parses the
file, because it will even do this without changing any attributes.
This whitespace damages readability, and bloats up the file.

Anyone know of a way to make the file look as it should, hopefully in
a pythonic way?
Mar 26 '07 #1
1 9688
Paul Kozik wrote:
However, if I use xml.minidom.parse to parse the xml document, change
a few attributes with setAttribute, then write back with toprettyxml,
my XML file gets loaded up with spaces between many of the elements.
Use 'toxml' method, that writes XML document without any modification.

w.
Mar 26 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by xtian | last post: by
2 posts views Thread by Vincent De Baere | last post: by
5 posts views Thread by Mike McGavin | last post: by
reply views Thread by Sullivan WxPyQtKinter | last post: by
2 posts views Thread by Peter Møllerud | last post: by
5 posts views Thread by fscked | last post: by
6 posts views Thread by Dan | last post: by
reply views Thread by Gary | last post: by
2 posts views Thread by JYA | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.