473,407 Members | 2,359 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,407 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 10039
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.