get element text in DOM?

Andrew Clover and-google at doxdesk.com
Sun Nov 14 05:14:52 EST 2004


Manlio Perillo <NOmanlio_perilloSPAM at libero.it> wrote:

>     for n in node.childNodes:
>         if n.nodeType in (dom.Node.TEXT_NODE, dom.Node.CDATA_SECTION_NODE):

(Aside: node.TEXT_NODE would probably be better here. Can't guarantee
that a DOM's implementation of the 'Node' interface is available as a
class called 'Node' inside its module.)

>             L.append(n.data)
>         else:
>             if not recursive:
>                 return None

Surely 'continue'? This will exit the function (returning None instead
of the expected empty string) the first time a non-Text node is met.

Incidentally, DOM Level 3 Core defines the property 'textContent' to
return pretty much exactly this (although it removes the ignorable
whitespace). Not in minidom yet, but... <insert usual plug here>

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the Python-list mailing list