Yes its very possible indeed. The trick is to use XPath variables. e.g.

import org.jaxen.SimpleVariableContext;

SimpleVariableContext variables = new SimpleVariableContext();
XPath xpath = doc.createXPath( "//foo[@doo=$x]" );
xpath.setVariableContext( variables );

Then you can set whatever variable value you want for 'x' and apply the
XPath to any node.

variables.setVariableValue( "x", "abc" );
List answer = xpath.selectNodes( document );
List answer = xpath.selectNodes( someNode );

etc.

James
----- Original Message -----
From: "Christian Holmqvist, IT, Posten" <[EMAIL PROTECTED]>
To: "'dom4j-user'" <[EMAIL PROTECTED]>
Sent: Friday, May 03, 2002 12:01 PM
Subject: [dom4j-user] Can I use XPath expression as prepared statements?


> Hi
>
> Is it possible to use XPath expressions as prepared statements?
>
> Example
> This is what I do now.
>
> public final static String XPATH_EXP = "//foo[@doo=?]";
> ....
> XPath xp = DocumentHelper.createXPath(XPATH_EXP.replace('?','1'));
> The problem with this is that replace only handles char... kind of
> limiting...
>
> I know it is possible to make it more complex.... but...
>
> What I would like to do is to define the XPath as
>
> public final static XPath XPATH_EXP =
> DocumentHelper.createXPath("//foo[@doo=?]");
> ...
> XPATH_EXP.setString(1, "foo");
> XPATH_EXP.selectNodes(doc);
> XPATH_EXP.setString(1, "oof");
> XPATH_EXP.selectNodes(doc);
>
> Is this possible, or have I missed something fundamental?
>
> /Cheers Christian
>
> _______________________________________________________________
>
> Have big pipes? SourceForge.net is looking for download mirrors. We supply
> the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to