get textual content of a Xml element using 4DOM

F

frankabel

Hi all!
I have the following xml file:
"
<items>
<item>hi</item>
<item>hello</item>
</items>
"
and need to read all the content between <items> and </items> tags and
saved in a string, in this case:
"
<item>hi</item>
<item>hello</item>
"
Working with "xml.dom.minidom" I can use the
"xml.dom.minidom.Node.toxml()" to obtain the string inside one node. But
I wish to use 4DOM to load my DOM tree.

Someone know a manner to make something like
"xml.dom.minidom.Node.toxml()" using 4DOM?

Why a lightweight implementation like "xml.dom.minidom" have this
feature, while a 4DOM don't?

Thanks
 
U

uche.ogbuji

I suggest using minidom or pxdom [1] rather than 4DOM. If you insist
on using 4DOM, xml.dom.ext.Print(node) or xml.dom.ext.PrettyPrint(node)
does what you want.

--Uche
 
F

Frank Abel Cancio Bello

Hi:

PrettyPrint or Print return the value to the console, and i need keep this
value in a string variable to work with it, how can i do this?

thanks to Uche

Frank Abel

-----Original Message-----
From: (e-mail address removed)
To: (e-mail address removed)
Date: 4 Mar 2005 09:23:07 -0800
Subject: Re: get textual content of a Xml element using 4DOM
 
A

and-google

Frank Abel Cancio Bello said:
PrettyPrint or Print return the value to the console, and i need
keep this value in a string variable to work with it, how can i
do this?

The second parameter to either of these functions can be a stream
object, so you can use a StringIO to get string output:

from StringIO import StringIO
from xml.dom.ext import Print

buf= StringIO()
Print(doc, buf)
xml= buf.getvalue()
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top