[lxml-dev] Possible bug in xpath?

Hi, I think I may have run into a bug. I'm attaching a sample code to reproduce it. Instead of getting back just the '<strong>..</strong>', I get the entire div content. Since I can't tell if this bug is in lxml or one of the libs it uses, I'm posting to this list instead of the bug tracker. My setup: Python 2.5.1, lxml 1.3.6 and libxml2.so.2.6.28. If OTOH I'm doing something stupid, just tell me :) Thanks a lot, -- Bruno Barberi Gnecco <brunobg_at_users.sourceforge.net> ...the flaw that makes perfection perfect.

Hi, Bruno Barberi Gnecco wrote:
I think I may have run into a bug. I'm attaching a sample code to reproduce it. Instead of getting back just the '<strong>..</strong>', I get the entire div content.
If OTOH I'm doing something stupid, just tell me :) Thanks a lot,
tostring(el) and tounicode(el) serialise the Element object you pass, and the .tail text of an Element is part of the Element object you are serialising. Try calling tounicode( et.getroot()[0] ) That should give you the same output that you see in your XPath example. Here's another example that might make it clear why this is so: >>> import lxml.etree as et >>> root = et.Element("test") >>> root.text = "TEXT" >>> et.tostring(root) <test>TEXT</test> >>> et.tail = "TAIL" >>> et.tostring(root) <test>TEXT</test>TAIL >>> et.tail = None >>> et.tostring(root) <test>TEXT</test> I also updated the FAQ entry on this topic. http://codespeak.net/lxml/dev/FAQ.html#what-about-that-trailing-text-on-seri... Stefan
participants (2)
-
Bruno Barberi Gnecco
-
Stefan Behnel