[lxml-dev] Next question (Was: Beginner question)

Andreas Tille tillea at rki.de
Tue Oct 16 18:54:21 CEST 2007


On Tue, 16 Oct 2007, Frederik Elwert wrote:

>            elif event == 'end'  and lname(elem) == 'vaccination':
>                print 'vaccination:', etree.tostring(elem,
> pretty_print=True)
>                try:
>                    print 'vaccination status response:',
> elem.xpath('./*[local-name() = "status"]')[0].get('response')
>                except IndexError:
>                    print 'status not found'

This works perfectly.

> Or you simply iter the children and test for lname():
>
>            elif event == 'end'  and lname(elem) == 'vaccination':
>                print 'vaccination:', etree.tostring(elem,
> pretty_print=True)
>                for child in elem:

This was the clue I was originally seeking for: I did not
imagined that it is so simple to iterate over elem itself.

>                    if lname(child) == 'status':
>                        print 'vaccination status response:',
> child.get('response')
>
>
> I cc'd this to the list, what I forgot to do before, since there are the 
> experts that might have better ideas.

Sure - I always prefer list replies.

Many thanks for your help

          Andreas.

-- 
http://fam-tille.de


More information about the lxml-dev mailing list