Take the 2-minute tour ×


 <bar key="value">text</bar>

How do I get "value"?


Throws an error.

share|improve this question
What's the error message? –  keegan3d Jan 1 '11 at 5:38

2 Answers 2

up vote 8 down vote accepted
In [52]: import xml.etree.ElementTree as ET

In [53]: xml=ET.fromstring(contents)

In [54]: xml.find('./bar').attrib['key']
Out[54]: 'value'
share|improve this answer

Your expression:


It means: bar children having key attribute

If you want to select the attribute, use this relative expression:


It means: the key attribute of bar children

Of course, you need to consider to use a full complain XPath engine like lxml: http://codespeak.net/lxml/xpathxslt.html

share|improve this answer
Not sure if it's ElementTree or Google App Engine but the use of '@' raises SyntaxError("unsupported path syntax (%s)" % op) SyntaxError: unsupported path syntax (@) –  Will Merydith Jan 1 '11 at 17:06
@Will Merydith: Please, read my last sentence. Basic ElementTree API it's not a full complain XPath engine... –  user357812 Jan 1 '11 at 17:09
OK. I'll see if I can find a module that will work on GAE/Py2.5.5. –  Will Merydith Jan 1 '11 at 17:14

Your Answer


