def find_spam(xml):
    for event, element in xml.etree.ElementTree.iterparse(xml):
        if element.tag == 'spam':
            print('We found a spam!')
yield element
How to return data from a Python SAX parser?