xml.dom.minidom question
Martin v. Loewis
martin at v.loewis.de
Mon May 20 17:00:04 EDT 2002
John <jdboy at mac.com> writes:
> How would I have to change getText to accomplish that?
You need to make this algorithm recursive:
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
if node.nodeType == node.ELEMENT_NODE: # added this
rc = rc + getText(node.childNodes)
return rc
Notice that adding strings like this can become a performance issue;
it might be better to collect the pieces in a list, and then use
string.join to flatten the list.
HTH,
Martin
More information about the Python-list
mailing list