xml.sax parsing elements with the same name
John Bokma
john at castleamber.com
Mon Jan 11 16:03:44 EST 2010
amadain <mfmdevine at gmail.com> writes:
> On Jan 11, 7:26 pm, John Bokma <j... at castleamber.com> wrote:
>> amadain <mfmdev... at gmail.com> writes:
>> > <event eventTimestamp="2009-12-18T08:22:49.035"
>> > uniqueId="1261124569.35725_PFS_1_1340035961">
>> > <result value="Blocked"/>
>> > <filters>
>> > <filter code="338" type="Filter_Name">
>> > <diagnostic>
>> > <result value="Triggered"/>
>> > </diagnostic>
>> > </filter>
>> > <filter code="338" type="Filter_Name">
>> > <diagnostic>
>> > <result value="Blocked"/>
>> > </diagnostic>
>> > </filter>
>> > </filters>
>> > </event>
> how do I keep track? The first result value is outside a filters
> section and the rest are. Do you mean something like:
>
> 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',"")
> if name == filters:
> if name == 'result':
> self.resultValueF = attrs.get('value',"")
> return
I was thinking about something like:
self.filterIndex = 0
in startElement:
if name == 'filter':
self.filterIndex += 1
return
if name == 'result' and self.filterIndex == 1:
... = attrs.get('value', '')
in EndElement
if name == 'filters':
self.filterIndex = 0
If you want the result of the first filter in filters
--
John Bokma
Read my blog: http://johnbokma.com/
Hire me (Perl/Python): http://castleamber.com/
More information about the Python-list
mailing list