[lxml-dev] xpath on text nodes

Stefan Behnel stefan_ml at behnel.de
Wed Apr 29 17:24:51 CEST 2009


Hi,

Jamie Norrish wrote:
> The xpath method is currently available only for ElementTree and Element
> objects. Is it possible for it to be available to text nodes also?

There is no such concept as a text node in lxml.etree.


> My current use case is getting a certain length text context for a
> particular element node, and I'd like to implement that through a
> recursive call to a function that returns the content of a supplied text
> node appended to the content of the next text node in sequence (provided
> the required length has not been passed).

That sounds a lot like you should do that in Python by using iterwalk()
and collecting .text and .tail attributes of Elements, not by using XPath.

Stefan



More information about the lxml-dev mailing list