[lxml-dev] problem\bug in xpath compare() with text in tail

Matan Ninio matan at xipus.lxmldev.ninio.org
Tue May 20 15:18:16 CEST 2008


This may be a just my (limited) understanding of Xpath and XML, but i'm getting
a strange problem when I try to use xpath to search for specific strings in a
file.  specifically, when I use "\\*[compare(text(),"needle")]" to look for
elements with "needle" in their text, it only works when the strings appears in
the "text" part, but not when its in the "tail" part.  So:

<prompt> e=etree.HTML("<html><body>inbody<h5>text</h5>tail</body></html>")

<prompt> e.xpath("//text()")
['inbody', 'text', 'tail']

<prompt> e.xpath("//*[contains(text(),'text')]//text()")
['text']

 ----  works fine, but

<prompt> e.xpath("//*[contains(text(),'tail')]//text()")
[]

 ----  does not.

is it just that I need to use a different function/attribute for the tail
(instead  of text())?   Is this a bug?  Is there a workaround?

using lxml 2.0.5, via mac "port"

thanks!



More information about the lxml-dev mailing list