473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 10023
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: xtian | last post by:
Hi - I'm doing some data conversion with minidom (turning a csv file into a specific xml format), and I've hit a couple of small problems. 1: The output format has a header with some xml that...
2
by: Vincent De Baere | last post by:
Hi I am playing around a little with python (I've started using python at 1 PM today, so I guess I could be considered a newbie :-)), and have come across a little problem regarding...
5
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some...
0
by: Sullivan WxPyQtKinter | last post by:
Hi, I am now using minidom for my current development. I use cloneNode method in Element object, but it just does not work. The test code is very simple as follows: =========CODE==============...
2
by: Peter Møllerud | last post by:
I'm very new to Python, so consider this a silly newbie question... Anyway, I'm building a small application to generate a XML. Using document from minidom, I'm doing something like : from...
5
by: fscked | last post by:
Hi guys/gals. I am trying to write and xml file from data parsed from a csv. I can get everything to work except that I cannot get minidom to do --> ö which needless to say is driving me nuts....
6
by: Dan | last post by:
I'm using python's xml.dom.minidom module to generate xml files, and I'm running into memory problems. The xml files I'm trying to create are relatively flat, with one root node which may have...
0
by: Gary | last post by:
Howdy I ran into a difference between Python on Windows XP and Linux Fedora 6. Writing a dom to xml with minidom works on Linux. It gives an error on XP if there is an empty namespace. The...
2
by: JYA | last post by:
Hi. I was writing an xmltv parser using python when I faced some weirdness that I couldn't explain. What I'm doing, is read an xml file, create another dom object and copy the element from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.