Xpath text() inconsistent with actual tree?
May 2, 2022
1:50 a.m.
Hello, Suppose I have the following example: xml = lxml.etree.XML("<a>one <b>two</b> <b>three</b> four</a>" Then: xml.xpath(".//text()") ['one ', 'two', ' ', 'three', ' four'] and lxml.etree.tostring(xml) b'<a>one <b>two</b> <b>three</b> four</a>' are both correct. Next, let me strip the <b> tags: lxml.etree.strip_tags(xml, "b") so that lxml.etree.tostring(xml) b'<a>one two three four</a>' and xml.text 'one two three four' are correct and expected. However, I did not expect the following: xml.xpath(".//text()") ['one ', 'two', ' ', 'three', ' four'] What’s going on here? Where does this inconsistency come from? Thanks! Jens -- Jens Tröger https://savage.light-speed.de/
1385
Age (days ago)
1385
Last active (days ago)
0 comments
1 participants
participants (1)
-
Jens Tröger