Re: [xml] Making xmlXPathEvalExpression only report "enough" matches



On Tue, Dec 07, 2004 at 03:00:39PM +0100, Aleksander Øhrn wrote:
Hi,

I'm using libxml2, and its XPath features in particular. When I invoke 

      xmlXPathObjectPtr xobj = xmlXPathEvalExpression(AsXMLchar(_expression.c_str()), ctx);

then

      xmlNodeSetPtr nodes = xobj->nodesetval;

gives me the set of all matches to my XPath expression. However, I use this in a piece of software where 
speed is rather important, and I don't really need all the matches. I only need the first n matches, where 
n is some configurable number.

Is there a way to make xmlXPathEvalExpression return when "enough" matches have been found, instead of 
having it return all matches? If yes, how?

  Answer is no. But there is kind of a similar optimization inside the
XPath engine to collect only the nth element in a list like in 
/foo[n] where n is a number, see xmlXPathNodeCollectAndTestNth().
What you would need is a special case for
     [position() < n]
     [position() <= n]
     [n > position()]
     [n >= position()]
You can dig xpath.c to try to implement this on top of the existing
xmlXPathNodeCollectAndTestNth().

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]