473,496 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fromatting an xml file

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!

Feb 2 '06 #1
2 1273
"sir_alex" <ch********@libero.it> writes:
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/...bedwriter.help
--
ha************@boeing.com 6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
Feb 3 '06 #2
sir_alex wrote:
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:
from Ft.Xml import Parse
from Ft.Xml.Domlette import PrettyPrint
XML = "<rootnode><node>bla</node><node>bla</node></rootnode>"
doc = Parse(XML)
PrettyPrint(doc) <?xml version="1.0" encoding="UTF-8"?>
<rootnode>
<node>bla</node>
<node>bla</node>
</rootnode>


http://4Suite.org

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

Feb 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3909
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
5429
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
3513
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
3
26236
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
3907
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
4280
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
5347
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
3
3146
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
0
2532
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
4
1082
by: Lit | last post by:
Hello, I get a web page, from java web server, via C# code but when I try to write the response I get from the web page to a text file it has lost of junk in it. \r\n\t\n\r\ etc... what...
0
7120
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
7160
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
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7373
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...
1
4897
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...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.