xml.sax parsing elements with the same name

amadain mfmdevine at gmail.com
Mon Jan 11 20:13:01 CET 2010

I have an event log with 100s of thousands of entries with logs of the

<event eventTimestamp="2009-12-18T08:22:49.035"
   <result value="Blocked"/>
          <filter code="338" type="Filter_Name">
                   <result value="Triggered"/>
          <filter code="338" type="Filter_Name">
                   <result value="Blocked"/>

I am using xml.sax to parse the event log. The trouble with the file
above is when I parse for result value I get the last result value
(Blocked from above). I want to get the result value triggered (the
second in the event).

my code is as follows:

    def startElement(self, name, attrs):
        if name == 'event':
            self.eventTime = attrs.get('eventTimestamp',"")
            self.eventUniqueId = attrs.get('uniqueId', "")
        if name == 'result':
            self.resultValue = attrs.get('value',"")

    def endElement(self, name):
        if name=="event":
            result= eval(self.filter)
            if result:

How do I get the result value I require when events have the same
names like above?

More information about the Python-list mailing list