[lxml-dev] ElementTree 1.3a xpath position broken?

hello, I am after xpath support for an application running on Google App Engine, which unfortunately rules out lxml. According to this document (http://effbot.org/zone/element-xpath.htm) the development version of ElementTree 1.3a has additional support for xpath, which covers my use cases.
From my tests I found attributes and child nodes work:
However tag positions appear to be broken:
print list(tree.findall('.//b[1]')) # should return b element []
Have I missed something? Suggestions? regards, Richard

Richard Baron Penman, 31.01.2010 05:06:
I am after xpath support for an application running on Google App Engine, which unfortunately rules out lxml.
Yeah, I know. That's one of the reasons I never found a use for the GAE on my side. That also makes your e-mail somewhat misplaced on this list. ;)
According to this document (http://effbot.org/zone/element-xpath.htm) the development version of ElementTree 1.3a has additional support for xpath,
Careful. It has *extended* the supported *subset* of XPath, compared to what ET 1.2 has. The ElementPath implementation was also completely rewritten and it's what lxml uses since 2.0.
which covers my use cases.
Apparently not. You can look at the sources to see what it supports. It's really quite short and simple. http://svn.effbot.org/public/elementtree-1.3/elementtree/ElementPath.py You may also want to look for "xpath" on this page: http://effbot.org/zone/element-index.htm That should get you here: http://sourceforge.net/projects/pdis-xpath/ I never tried it, but it's been recently updated, so it looks like it's still maintained.
That shouldn't be hard to add. You just have to make sure it only counts elements within the same parent, so you may have to add the selector in more than one place. I guess that's why Fredrik didn't add it while he was at it. Stefan

hi Stefan, thanks very much for your reply.
Hopefully the lxml feature request goes somewhere: http://code.google.com/p/googleappengine/issues/detail?id=18 Can you recommend an alternative for discussing ElementTree? I tried emailing Fredrik earlier but didn't get a response and the ElementTree repository hasn't been committed to since 2007. http://sourceforge.net/projects/pdis-xpath/
I never tried it, but it's been recently updated, so it looks like it's still maintained.
That project does look promising, however it doesn't yet support // or ..
I found it was half implemented and finished it off. There is some elegant code in ElementPath.py but it needs refactoring... Richard

Richard Baron Penman, 31.01.2010 14:56:
Intestering. Yes, let's see what that gives. Everyone's invited to vote for that bug, obviously.
Fredrik is rather packed with other stuff these days. Note that ET 1.3 may make it into 3.2/2.7: http://bugs.python.org/issue1143 So c.l.py and the Python bug tracker are suitable places. For implementation specific questions, there is also python-dev and the stdlib sig mailing list.
I believe that it lacks support for '..' (although that's trivial to implement even with ET), but '//'???
Care to provide a patch? Stefan

On Tue, Feb 2, 2010 at 6:18 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
hmm, not sure that is a good idea if ET was not maintained recently.
Yep - no // support. And I found out (from Ken Riley) that pdis is no longer maintained.
To who? Fredrik seems busy... So I plan to fork ElementPath.py with my own updates and then release as a standalone ElementTree xpath library like pdis. Also I aim to add support for absolute xpaths, for compatibility with my existing lxml dependent code. Richard

Richard Baron Penman, 02.02.2010 01:56:
To lxml - remember what list we have this discussion on? Also, to the Python bug tracker. I doubt that a new feature like this would be rejected.
That's also an option, and a good one IMHO. That would make it easily available to both ET and lxml. (Advantage for lxml being the incremental search support which is not available in XPath). Please take a look at both implementations, the one in ET 1.3 and the one in lxml. http://codespeak.net/svn/lxml/trunk/src/lxml/_elementpath.py There are some minor differences that make the latter one run faster on top of lxml's advanced tree iterators. Stefan

Richard Baron Penman, 31.01.2010 05:06:
I am after xpath support for an application running on Google App Engine, which unfortunately rules out lxml.
Yeah, I know. That's one of the reasons I never found a use for the GAE on my side. That also makes your e-mail somewhat misplaced on this list. ;)
According to this document (http://effbot.org/zone/element-xpath.htm) the development version of ElementTree 1.3a has additional support for xpath,
Careful. It has *extended* the supported *subset* of XPath, compared to what ET 1.2 has. The ElementPath implementation was also completely rewritten and it's what lxml uses since 2.0.
which covers my use cases.
Apparently not. You can look at the sources to see what it supports. It's really quite short and simple. http://svn.effbot.org/public/elementtree-1.3/elementtree/ElementPath.py You may also want to look for "xpath" on this page: http://effbot.org/zone/element-index.htm That should get you here: http://sourceforge.net/projects/pdis-xpath/ I never tried it, but it's been recently updated, so it looks like it's still maintained.
That shouldn't be hard to add. You just have to make sure it only counts elements within the same parent, so you may have to add the selector in more than one place. I guess that's why Fredrik didn't add it while he was at it. Stefan

hi Stefan, thanks very much for your reply.
Hopefully the lxml feature request goes somewhere: http://code.google.com/p/googleappengine/issues/detail?id=18 Can you recommend an alternative for discussing ElementTree? I tried emailing Fredrik earlier but didn't get a response and the ElementTree repository hasn't been committed to since 2007. http://sourceforge.net/projects/pdis-xpath/
I never tried it, but it's been recently updated, so it looks like it's still maintained.
That project does look promising, however it doesn't yet support // or ..
I found it was half implemented and finished it off. There is some elegant code in ElementPath.py but it needs refactoring... Richard

Richard Baron Penman, 31.01.2010 14:56:
Intestering. Yes, let's see what that gives. Everyone's invited to vote for that bug, obviously.
Fredrik is rather packed with other stuff these days. Note that ET 1.3 may make it into 3.2/2.7: http://bugs.python.org/issue1143 So c.l.py and the Python bug tracker are suitable places. For implementation specific questions, there is also python-dev and the stdlib sig mailing list.
I believe that it lacks support for '..' (although that's trivial to implement even with ET), but '//'???
Care to provide a patch? Stefan

On Tue, Feb 2, 2010 at 6:18 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
hmm, not sure that is a good idea if ET was not maintained recently.
Yep - no // support. And I found out (from Ken Riley) that pdis is no longer maintained.
To who? Fredrik seems busy... So I plan to fork ElementPath.py with my own updates and then release as a standalone ElementTree xpath library like pdis. Also I aim to add support for absolute xpaths, for compatibility with my existing lxml dependent code. Richard

Richard Baron Penman, 02.02.2010 01:56:
To lxml - remember what list we have this discussion on? Also, to the Python bug tracker. I doubt that a new feature like this would be rejected.
That's also an option, and a good one IMHO. That would make it easily available to both ET and lxml. (Advantage for lxml being the incremental search support which is not available in XPath). Please take a look at both implementations, the one in ET 1.3 and the one in lxml. http://codespeak.net/svn/lxml/trunk/src/lxml/_elementpath.py There are some minor differences that make the latter one run faster on top of lxml's advanced tree iterators. Stefan
participants (2)
-
Richard Baron Penman
-
Stefan Behnel