I have been using the DOM Level 3 XPath support in Xerces 2.5 for boolean
matching and am quite happy with it.
Under the covers, does this go over the XPathApi? Sorry - no time to look
at the source :(
-chris
Joaquín Sánchez
Jiménez
<[EMAIL PROTECTED] To
> "Siljan Simpson"
<[EMAIL PROTECTED]>,
06/26/2003 07:54 <[EMAIL PROTECTED]>
PM cc
Subject
Re: usage of XPath
Hi again:
This is the original source code for:
public XObject eval(
Node contextNode, String str, PrefixResolver prefixResolver)
throws TransformerException
XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
// Execute the XPath, and have it return the result
XPathContext xpathSupport = new XPathContext();
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
First at all add a Hashtable to the object, for exmaple:
private final Hashtable ctxts = new Hashtable();
Then
public XObject eval(
Node contextNode, String str, PrefixResolver prefixResolver)
throws TransformerException
XPath xpath = null;
if(ctxts.get(new Integer(prefixResolver.hashCode())) == null) {
xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
ctxts.put(new Integer(prefixResolver.hashCode()), xpath);
} else {
xpath = (XPath)ctxts.get(prefixResolver.hashCode());
}
// Execute the XPath, and have it return the result
XPathContext xpathSupport = new XPathContext();
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
What compile the expression is XPath object, so you must cache this object
via its prefix resolver. See XPath source code to see how it works.
Bye.
J.
----- Original Message -----
From: "Siljan Simpson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 26, 2003 7:24 PM
Subject: Re: usage of XPath
> Thanks for the response.
>
> CachedXPathAPI generates the classes needed for XPathContext (DTMManager
and DTMs). But if I use the same XPath repeatedly, the XPath is compiled
everytime and not cached.
>
> Is there someway I can reuse the compiled-XPath ?
>
> -Siljan
>
>
> ----- Original Message -----
> From: Joaquín_Sánchez_Jiménez <[EMAIL PROTECTED]>
> Date: Thu, 26 Jun 2003 19:06:39 +0200
> To: "Siljan Simpson" <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
> Subject: Re: usage of XPath
>
> > Hi:
> >
> > XPath API is slow because each time you invoke it it must compile the
> > expression (in fact must get a XPathContext). CachedXPathAPI can be
used
> > along the time while the node to parse not change. So first time is
slow
> > (the same as XPathAPI) but next calls this class not need to recompile
the
> > expression.
> >
> > Read CachedXPathAPI javadoc API.
> >
> > You can see an samples looking in XPathAPI source code.
> >
> > Bye.
> >
> > J.
> >
> > ----- Original Message -----
> > From: "Siljan Simpson" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, June 26, 2003 6:32 PM
> > Subject: usage of XPath
> >
> >
> > > Hi,
> > >
> > > I am working on a project using XML. Presently we are using
CachedXPathAPI
> > to get a Node based on the XPath evaluation. From the documentation I
> > understand that this method is slow and compiling the XPath will be
> > efficient.
> > >
> > > Does anyone have a sample code on how the XPath can be compiled and
used
> > to extract nodes ?
> > >
> > > Any pointers will be appreciated.
> > >
> > > Thanks,
> > > Siljan
> > > --
> > > __________________________________________________________
> > > Sign-up for your own FREE Personalized E-mail at Mail.com
> > > http://www.mail.com/?sr=signup
> > >
> > >
> >
>
> --
> __________________________________________________________
> Sign-up for your own FREE Personalized E-mail at Mail.com
> http://www.mail.com/?sr=signup
>
>