[Tutor] Parsing XML with minidom - problem solved
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Jul 8 22:04:21 CEST 2004
On Thu, 8 Jul 2004, Ertl, John wrote:
> I guess to get to the data I need to look at the childNode of each.
>
> each.childNodes[0].data
Hi John,
Yeah; the weird thing that trips everyone up at least once (... or
twice... *grin*) in DOM xml is this: the text within each element is
itself a node.
In fact, it's very possible for something like:
<foo>this is a test. can you see this?</foo>
to be made up of several child "text" nodes. It's not sufficient just to
look at the first child node to get at the text --- although it works for
simple cases, it'll break if the text is long enough to be split into
separate child nodes.
See:
http://www.python.org/doc/lib/dom-example.html
and, in particular, take a look at the "getText()" function and the way
that the example uses getText().
Hope this helps!
More information about the Tutor
mailing list