Lxml Findall Syntaxerror: Invalid Predicate
I'm trying to find elements in xml using xpath. This is my code: utf8_parser = etree.XMLParser(encoding='utf-8') root = etree.fromstring(someString.encode('utf-8'), parser=utf8_par
Solution 1:
Switching from xpath()
to findall()
is not a solution. The latter only supports subset of XPath 1.0 expression (compatible to xml.etree.ElementTree
's XPath support), and your attempted expression happen to be part of the unsupported subset.
The actual problem is, that root
variable already references model
element, so you don't need to mention "model"
again in your XPath :
somelist = root.xpath("class[*/attributes/attribute/@name='var']/@name")
Post a Comment for "Lxml Findall Syntaxerror: Invalid Predicate"