[Tutor] ElementTree: finding a tag with specific attribute

Bernard Lebel 3dbernard at gmail.com
Fri Sep 16 21:21:03 CEST 2005


With ElementTree, can you search a tag under an Element by not only
specifying the tag label, but also some tag attribute values? That
would be in the case where I have several tags with the same label but
with various attribute values.

Right now I do a loop over every tag of the same label, then test the

for oTag in oElement.findall( 'taglabel' ):
    if oTag.attrib[ 'value' ] == 'xx': do something

I'm looking for something a bit like BeautifulSoup, like:

oTag = oElement.find( 'taglabel', { 'value' : 'xx' } )

Btw in case you wonder, I don't use BeautifulSoup because somehow it
takes 20-30 seconds to parse a 2000-line xml file, and I don't know
why. ElementTree is proving very performing.


More information about the Tutor mailing list