Take the 2-minute tour ×

I'm trying to get some elements from a svg using xpath. I'm trying to get nodes via their class. For example:

<path d="M 5624850,7744480 A 355600,355600 0 0,1 5624850,8455680 A 355600,355600 0 0,1 5624850,7744480" stroke-width="7620" fill="none" class="outline LAY26"/>

So, if I want the class with 'outline' and 'L26', I do the following one:

elements = self.node.findall(".//*[@class='outline LAY26']")

However I always get an empty array. The nodes that I'm looking for can be nested. So I think i'm looking just in the first level, maybe I'm wrong.

Any ideas?

share|improve this question
Using elementree - have you tried just self.node.findall("[@class='outline LAY26']") ? –  Jon Clements Nov 23 '12 at 11:31
@JonClements yeah, and I get nothing. –  Ruben Nov 23 '12 at 11:33
pivotallabs.com/users/alex/blog/articles/… Try this way. findall(".//*[contains(concat(' ',normalize-space(@class),' '),' outline ' and contains(concat(' ',normalize-space(@class),' '),' LAY26 '))]") –  杨扬-momo Nov 23 '12 at 11:35
@iMom0 it says the syntaxis is incorrect :( –  Ruben Nov 23 '12 at 12:27
@iMom0 That syntax isn't valid for xml.etree.ElementTree as it only supports limited XPath - and wouldn't apply anyway, as it's a valid literal comparison instead of looking for a class name inside a list of classes –  Jon Clements Nov 23 '12 at 12:38
add comment


Your Answer



Browse other questions tagged or ask your own question.