That's a great chance to start findall vs xpath battle again =) I think lxml should eliminate .xpath method and implement .find* methods through libxml2 xpath support. On Fri, 2006-05-26 at 04:42 -0300, Steve Howe wrote:
Hello all,
How compatible are the findall() and xpath() methods ? findall() don't seem to handle more complicated XPath expressions. Why there is a difference between what they can handle ?
I would expect findall() to be the same as xpath(), but searching from the context node and always returning a list of items, making it compatible with ET's.
An example:
Python 2.4.3 (#2, Apr 17 2006, 14:29:19) [GCC 3.4.4 [FreeBSD] 20050518] on freebsd6 Type "help", "copyright", "credits" or "license" for more information.
from lxml import etree root = etree.XML('''<obj class="list"> ... <obj class="str" value="xxx"/> ... </obj>''') print root.xpath('obj[not(@name)]') [<Element obj at 81daa2c>] print root.findall('obj[not(@name)]') Traceback (most recent call last): File "<stdin>", line 1, in ? File "etree.pyx", line 937, in etree._Element.findall File "/usr/local/lib/python2.4/site-packages/lxml-1.0.beta-py2.4-freebsd-6.1-RELEASE-i386.egg/lxml/_elementpath.py", line 193, in findall return _compile(path).findall(element) File "/usr/local/lib/python2.4/site-packages/lxml-1.0.beta-py2.4-freebsd-6.1-RELEASE-i386.egg/lxml/_elementpath.py", line 171, in _compile p = Path(path) File "/usr/local/lib/python2.4/site-packages/lxml-1.0.beta-py2.4-freebsd-6.1-RELEASE-i386.egg/lxml/_elementpath.py", line 87, in __init__ raise SyntaxError( SyntaxError: expected path separator ([)