D
David Portabella
Hello,
I am using XPathAPI class.
The problem that I have is that after using XObject object =
XPathAPI.eval(node, xpathStr)
on 1000 different nodes (same xpathStr), it really becomes very slow.
This behavior is indeed documented in the documentation of XPathAPI:
http://xml.apache.org/xalan-j/apidocs/org/apache/xpath/XPathAPI.html
++++++
The methods in this class are convenience methods into the low-level
XPath API. These functions tend to be a little slow, since a number of
objects must be created for each evaluation. A faster way is to
precompile the XPaths using the low-level API, and then just use the
XPaths over and over. NOTE: In particular, each call to this method
will create a new XPathContext, a new DTMManager... and thus a new
DTM. That's very safe, since it guarantees that you're always
processing against a fully up-to-date view of your document. But it's
also portentially very expensive, since you're rebuilding the DTM
every time. You should consider using an instance of CachedXPathAPI
rather than these static methods.
+++++++
The explanation talks about precompiling the XPaths using the low-
level API, and then just use the XPaths over and over.
How to do this?
I would need something like:
++++++++++++
compiledXPath = XXX.compileXPath(xpathStr);
....
and then run this for 1000 different nodes:
XObject object = compiledXPath.eval(node)
++++++++++++
Do you know how to do this?
Regards,
DAvid
I am using XPathAPI class.
The problem that I have is that after using XObject object =
XPathAPI.eval(node, xpathStr)
on 1000 different nodes (same xpathStr), it really becomes very slow.
This behavior is indeed documented in the documentation of XPathAPI:
http://xml.apache.org/xalan-j/apidocs/org/apache/xpath/XPathAPI.html
++++++
The methods in this class are convenience methods into the low-level
XPath API. These functions tend to be a little slow, since a number of
objects must be created for each evaluation. A faster way is to
precompile the XPaths using the low-level API, and then just use the
XPaths over and over. NOTE: In particular, each call to this method
will create a new XPathContext, a new DTMManager... and thus a new
DTM. That's very safe, since it guarantees that you're always
processing against a fully up-to-date view of your document. But it's
also portentially very expensive, since you're rebuilding the DTM
every time. You should consider using an instance of CachedXPathAPI
rather than these static methods.
+++++++
The explanation talks about precompiling the XPaths using the low-
level API, and then just use the XPaths over and over.
How to do this?
I would need something like:
++++++++++++
compiledXPath = XXX.compileXPath(xpathStr);
....
and then run this for 1000 different nodes:
XObject object = compiledXPath.eval(node)
++++++++++++
Do you know how to do this?
Regards,
DAvid