By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

XML minidom Parsing and ToPrettyXML

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.