Hi Martijn, Martijn Faassen wrote:
This reminds me, I was talking to someone who was interested in getting a function that would just give the first xpath result by the way - equivalent to find(), I think. Often you know you find just one thing, and you want it to return that, instead of having to grap things from the resulting list of nodes. Of course underneath it'd still do the same search, so this would be purely a convenience API, not a performance gain.
Yeah, sadly, libxml2 doesn't have any routines for stopping XPath once a result has been matched. But then, XPath is pretty complex, how do you actually know when you have a result that will be passed through to the caller? But then, that's basically what _elementpath does, too: find everything and return the first result. I wouldn't mind having something like xpath1() to return the first hit only. On the other hand, are there any substantial differences in the ElementTree Path syntax with respect to an XPath subset that should keep us from having findall() etc. call XPath directly? Stefan