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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google App Engine
ElementTree uses XPath which uses square brackets to indicate filters:
//col[@name="ralf"]