from xml.sax import saxutils
from xml.sax import make_parser
from xml.sax.handler import feature_namespaces

class FindIssue(saxutils.DefaultHandler):
    def __init__(self, date):
        self.search_date = date

    def startElement(self, name, attrs):
        # If it's not a day element, ignore it
        if name != 'day': return

        # Look for the title and number attributes (see text)
        date = attrs.get('date', None)
        if (date == self.search_date):
            print title, 'date: ' + str(date), ' found'
            
if __name__ == '__main__':
    # Create a parser
    parser = make_parser()

    # Tell the parser we are not interested in XML namespaces
    parser.setFeature(feature_namespaces, 0)

    # Create the handler
    dh = FindIssue('1')

    # Tell the parser to use our handler
    parser.setContentHandler(dh)

    # Parse the input
    file = open('data.dat')
    parser.parse(file)
    file.close()
    
