[Tutor] How to get a string from a DOM Text node ?
Dave Kuhlman
dkuhlman at rexx.com
Tue May 27 02:02:51 CEST 2008
On Sun, May 25, 2008 at 11:10:19PM +0100, Alan Gauld wrote:
>
> "Zameer Manji" <zmanji at gmail.com> wrote in
> >
> >The problem is that the Text node that is printed out is blank, when
> >it
> >should be 42. What do I need to do so I can get tdict.childNodes[2]
> >to
>
> I may be off base here; I only used DOM once. I usually use
> ElementTree for parsing XML(and only rarely do that!). But isn't there
> a data or content field on the tag object that you have to use?
>
I second Alan's suggestion that you use ElementTree instead of
minidom. It's in the Python 2.5 standard library now. And, you
can find documentation here:
http://effbot.org/zone/element-index.htm
But, if you do stick with minidom, then I believe that you want
something like this:
if node.nodeType == node.TEXT_NODE:
print 'characters: "%s"' % (node.data, )
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
More information about the Tutor
mailing list