Fromatting an xml file

S

sir_alex

Hi! I have a little problem writing xml files formatted in a way like
the following:

<rootnode>
<node>bla</node>
<node>bla</node>
</rootnode>

Every new node element should have a tabulation before it, but when I
use xml.dom.minidom I use writexml, which considers as a new node also
the text (in my little example, "bla" phrases), so the best result I
achieved has been the following

<rootnode>
<node>
bla
</node>
</rootnode>

but I don't want the text to be written on newlines... is there a good
solution? Thanks!
 
H

Harry George

sir_alex said:
Hi! I have a little problem writing xml files formatted in a way like
the following:

<rootnode>
<node>bla</node>
<node>bla</node>
</rootnode>

Every new node element should have a tabulation before it, but when I
use xml.dom.minidom I use writexml, which considers as a new node also
the text (in my little example, "bla" phrases), so the best result I
achieved has been the following

<rootnode>
<node>
bla
</node>
</rootnode>

but I don't want the text to be written on newlines... is there a good
solution? Thanks!

Based on recommendations from this newsgroup, I write XML directly,
instead of going through DOM. That in turn requires a mechanism for
tabbed indents, so I wrote tabbedwriter:

http://www.seanet.com/~hgg9140/comp/index.html
http://www.seanet.com/~hgg9140/comp/tabbedwriter/doc/tabbedwriter.help
 
U

uche.ogbuji

sir_alex said:
Hi! I have a little problem writing xml files formatted in a way like
the following:

<rootnode>
<node>bla</node>
<node>bla</node>
</rootnode>

Every new node element should have a tabulation before it, but when I
use xml.dom.minidom I use writexml, which considers as a new node also
the text (in my little example, "bla" phrases), so the best result I
achieved has been the following

<rootnode>
<node>
bla
</node>
</rootnode>

but I don't want the text to be written on newlines... is there a good
solution? Thanks!

That minidom behavior is fairly unsafe. 4Suite's PrettyPrinter is much
safer:
<?xml version="1.0" encoding="UTF-8"?>
<rootnode>
<node>bla</node>

http://4Suite.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top