Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XPath 2

 
Marco Rossi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you'll need to find an implementation which supports Xpath 2.0 queries.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic