This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: XPath in Java Q?


> I am not sure if this is the right place for this post, but
> anyway I would
> like to ask if there is a way how to query xml document in
> Java using XPath
> (e.g. some free library etc.).
>
Quite a few products offer this capability.

You can do it in Saxon, though it's perhaps a little bit cumbersome:

Expression exp = Expression.make("2+2", new StaticContext());
Context cxt = ((Controller)transformer.newContext();
System.err.println(exp.evaluateAsString(cxt));

will output "4".

The "transformer" is obtained from JAXP in the normal way. Really, this is
intended primarily for use within XSLT extension functions, where the
"context" object will be supplied in the calling parameters. But you can
also use it in a freestanding application, as illustrated in the
ShowBooks.java sample application issued with the product.

Saxon's XPath processor will run against Saxon's own internal tree format,
or against a JDOM tree. It won't run against a third-party DOM, unless you
do a lot of interfacing work.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]