Nested XPath selects on text nodes does not work

Bug #996134 reported by Alexandru Cepoi on 2012-05-07
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Wishlist
Unassigned

Bug Description

Text nodes are not returned as a lxml.etree._Element, but rather lxml.etree._ElementStringResult which does not have the xpath method. Thus nesting selectors on text nodes does not work. The following illustrates this rather well:

### BUG
from lxml import etree
string = "<div><b>Options:</b>opt1</div><div><b>Other</b>opt2</div>"
html = etree.fromstring(string, parser=etree.HTMLParser(recover=True, encoding='utf8'))
x1 = html.xpath("//div/descendant::text()")
x2 = x1[0].xpath("./preceding-sibling::b") # => AttributeError: '_ElementStringResult' object has no attribute 'xpath'
### ---

Python : sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)
lxml.etree : (2, 3, 4, 0)
libxml used : (2, 7, 8)
libxml compiled : (2, 7, 8)
libxslt used : (1, 1, 26)
libxslt compiled : (1, 1, 26)

scoder (scoder) wrote :

This is a feature request.

Changed in lxml:
importance: Undecided → Wishlist
status: New → Triaged
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers