[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|