XML Parsing: How to find all elements with specific attribute value?

1,091 views
Skip to first unread message

BeSharp

unread,
Feb 4, 2009, 10:03:17 AM2/4/09
to Google App Engine
I'm not a native Python developer but found the learning curve pretty
okay. However, I'm currently stuck in processing an XML document. I'm
trying to use ElementTree and it basically works fine. I've got to get
all elements with a specific value for an attribute. Here is what I've
tried:

result = tree.findall('col@name="ralf"')

As to the ElementTree documentation this is supposed to return all
<col> elements where the attribute "name" has the value "ralf", e.g.
the following element would qualify:

<col name="ralf">

I do receive the following error:

SyntaxError: expected path separator (@)

Can anybody shed some light on this, please?

Blixt

unread,
Feb 4, 2009, 11:39:28 AM2/4/09
to Google App Engine
ElementTree uses XPath which uses square brackets to indicate filters:
//col[@name="ralf"]
Reply all
Reply to author
Forward
0 new messages