MCPcopy Create free account
hub / github.com/ActiveState/code / getTextFromNode

Function getTextFromNode

recipes/Python/409899_xmlreader2/recipe-409899.py:17–29  ·  view source on GitHub ↗

scans through all children of node and gathers the text. if node has non-text child-nodes, then NotTextNodeError is raised.

(node)

Source from the content-addressed store, hash-verified

15
16
17def getTextFromNode(node):
18 """
19 scans through all children of node and gathers the
20 text. if node has non-text child-nodes, then
21 NotTextNodeError is raised.
22 """
23 t = ""
24 for n in node.childNodes:
25 if n.nodeType == n.TEXT_NODE:
26 t += n.nodeValue
27 else:
28 raise NotTextNodeError
29 return t
30
31
32def nodeToDic(node):

Callers 1

nodeToDicFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected