aspose file tools*
The moose likes XML and Related Technologies and the fly likes XPath 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath 2" Watch "XPath 2" New topic
Author

XPath 2

Marco Rossi
Ranch Hand

Joined: Jul 01, 2011
Posts: 30
Hi all,

in my application I need to make some queries to an external XML file and I am using XPath.

Java6 (and 7 too) offers support to XPath1.0 but I need to build some complex XPath expressions that only work in XPath 2.

At the moment, this is what I am doing:



What should I use and do if I want to switch to XPath?

Thanks
Marco
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I think you'll need to find an implementation which supports Xpath 2.0 queries.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
The Saxon library supports XPath 2.0. I wouldn't hold my breath for either Jaxen or Xalan to support it, not for it to become part of the standard class libraries.
Marco Rossi
Ranch Hand

Joined: Jul 01, 2011
Posts: 30
I am trying with Saxon but I do not find any good examples...

is it enough to do that?



where XPathFactoryImpl() is net.sf.saxon.xpath.XPathFactoryImpl;

but what about XPathExpression?

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
>I am trying with Saxon but I do not find any good examples...
I can give you a complete working demo with null xml document. It tests xpath 2.0 specific suppoted function. I would expect you say "good". It still takes effort to do test or anything at all for that matter.

[0] Add saxon9j.jar and saxon9.jar and saxon9-xpath.jar. (Or some other version, if applicable.)

[1] Only one specific saxon related import statement you need to add (among other according to need.)

(Not even need if you tolerate writing out the full package.)

[2] This is the method to be called upon in the test program.

Marco Rossi
Ranch Hand

Joined: Jul 01, 2011
Posts: 30
I tried to execute an XPath 2.0 Expression and it works.
What I have done is simply (I found this code on another website):



Your way and mine are similar, by the way.

I tried with your implementation and my application works fine too, thanks.

Marco

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XPath 2