I am trying to get the text between the xml tags. There are several posts about it, but what I don't understand is how to save it in a variable. The code below prints what I want, but as soon as I replace "print" with "return" it doesn't save this text in the variable. I think I am missing something very simple here.
from xml.sax import make_parser, handler
line = '<text><p><s id="1">Some text <someothertag>some more text</someothertag></s></p></text>'
class extract_text(handler.ContentHandler):
def characters(self, data):
print data.strip()
parser = make_parser()
parser.setContentHandler(extract_text())
parser.feed(line)
So I would like to have a variable, which would be equal to "Some text some more text" Any idea is very welcome!