By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,247 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,247 IT Pros & Developers. It's quick & easy.

get textual content of a Xml element using 4DOM

P: n/a
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


Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Jul 18 '05 #2

P: n/a
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.

[1] http://www.doxdesk.com/software/py/pxdom.html

--Uche

Jul 18 '05 #3

P: n/a
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: uc*********@gmail.com
To: py*********@python.org
Date: 4 Mar 2005 09:23:07 -0800
Subject: Re: get textual content of a Xml element using 4DOM
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.

[1] http://www.doxdesk.com/software/py/pxdom.html

--Uche

--
http://mail.python.org/mailman/listinfo/python-list



Jul 18 '05 #4

P: n/a
Frank Abel Cancio Bello <FRANKA...@esla.cujae.edu.cu> wrote:
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()

--
Andrew Clover
http://www.doxdesk.com/
mailto:an*@doxdesk.com

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.