+def _collect_text(node):
+ text_accumulator = []
+ for element in node.childNodes:
+ if element.localName:
+ continue
+ elif element.nodeType == element.COMMENT_NODE:
+ text = u"<!--%s-->" % element.nodeValue
+ elif element.nodeType == element.TEXT_NODE:
+ text = element.nodeValue.strip()
+ else:
+ xml_error("Unknown node type %d" % element.nodeType)
+ if text: text_accumulator.append(text)
+ return '\n'.join(text_accumulator).encode(default_encoding, "replace")
+