Good XPath API for Java?

J

JS

I am trying to learn XPath and would therefore like to be able to execute
various XPath statements on different XML files. I have heard that the best
way to do this is to find an XPath API for eg. java and then write some
small applications. So far I have been looking at:


http://xml.apache.org/xalan-j/xpath_apis.html

But are there any alternatives that should be considered?
 
M

Martin Honnen

JS said:
I am trying to learn XPath and would therefore like to be able to
execute various XPath statements on different XML files. I have heard
that the best way to do this is to find an XPath API for eg. java and
then write some small applications. So far I have been looking at:


http://xml.apache.org/xalan-j/xpath_apis.html

But are there any alternatives that should be considered?

I am not sure you need to write an application yourself. The jEdit
editor for instance has an XSLT/XPath plugin that allows you to evaluate
XPath expressions against an XML document. And I am sure that is just an
example, there are certainly other tools already providing XPath evaluation.

As for alternatives, if you want to learn and use XPath 1.0 then I think
the javax.xml.xpath API is fine but since 2007 we have XPath 2.0 (and
XQuery 1.0 of which XPath 2.0 is a subset) so you could consider to use
Saxon from http://saxon.sourceforge.net/ to use the more powerful XPath
2.0 or XQuery 1.0 language.
 
J

Joe Kesselman

http://xml.apache.org/xalan-j/xpath_apis.html

Those are essentially the JAXP/TrAX APIs, which are a de facto
semi-standard for invoking XPaths from Java... though other
implementations may use other APIs.

If you just want to experiment with XPaths, most XPath implementations
(including Xalan) come with sample programs which will let you execute
an XPath from the command line (or which can easily be tweaked into that
form.)

As Martin said, you could also consider finding a tool which supports
XPath and using it as your "experimental" environment. I originally
learned XPath mostly in the context of using it from XSLT.

Whether you want to jump straight to the 2.0 versions of these depends
in part on where you're going to be using them. 2.0 does add a lot of
nice features, but it isn't supported everywhere yet (as the Apache code
illustrates), so it may be worth considering learning 1.0 first and then
adding on the 2.0 changes rather than learning 2.0 and then discovering
what has to be trimmed out in a 1.0 environment. And in fact, for the
most common uses of XPath, the difference between 1.0 and 2.0 isn't very
significant. (That may change as people start using Schema-sensitive
paths more often, admittedly.)
 
P

Philippe Poulard

JS a écrit :
I am trying to learn XPath and would therefore like to be able to
execute various XPath statements on different XML files. I have heard
that the best way to do this is to find an XPath API for eg. java and
then write some small applications. So far I have been looking at:


http://xml.apache.org/xalan-j/xpath_apis.html

But are there any alternatives that should be considered?

Hi,

Jaxen is also a good one:
http://jaxen.codehaus.org/

It is the XPath engine used in RefleX:
http://reflex.gforge.inria.fr/

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top