Vous êtes sur la page 1sur 4

XPath Evaluator

in
Eclipse Galileo

Knowledge Level: Beginner-Intermediate

There is a lack of quality open source java tools in XML Space, but luckily with recent
enhancements in Eclipse and NetBeans things are changing drastically. These IDEs not only
provide the Graphical Development of XML and XSDs, they also provide XSL transformation
capabilities which allows you to run XSL transformations over a XML file and see the result on
the fly, some of these tools use standard Xalan for transformation and executing XSL files.

For now let’s see the XPath capabilities of Eclipse and this post will be followed by the “XSL
transformations in Eclipse Galileo” in near future.

To start with you need to go through the following tutorial to grasp the base concepts of XML
XPath.

XML Tutorial: http://www.w3schools.com/xml/default.asp

XPath Tutorial: http://www.w3schools.com/XPath/default.asp

If you want to grasp the internal concepts on which XPath is dependent on then you have to read the
following specifications of W3C :

Document Object Model XPath @ http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html


Start the eclipse, and in your workspace, just create a general project:

In the new project wizard select General -> Project and click “Next” and provide a project name as
“XSLT” or any other valid name.

Provide a project name as “XSLT” or any other valid name.

Change your eclipse perspective to XML using the files tool bar -> Window -> Open Perspective ->

Other … -> Select “XML”.

The below screen shot shows the exact XML perspective with various windows highlighted:

XML Outline

XPath Evaluator
XSL Templates

Now let’s use a sample XML and see how to evaluate XPath expressions on it.

XPath is used to navigate through elements and attributes in an XML document.

To learn more about XPath go to W3C Schools XPath tutorial.

Let’s use the Books.xml specified at W3C examples and to do that we need to create a new XML
document in our XSLT project of eclipse.

To do this right click on the project -> New -> XML and type filename as books.xml and click finish.
Eclipse displays the opened XML in two views namely design and source view, switch to source view and
copy paste the content of books.xml specified at W3C examples.

Now we can see that the XPath Evaluator window and XML outline windows updates to show the new
books.xml content.

Now we are ready to execute the XPath expressions in the XPath Evaluator.

Let’s start with “//*” which stands for all the elements in the target XML file type “//*” in XPath
Evaluator and see the result as shown below, let’s try to select a books with category as WEB.
Similarly we can execute any XPath expression on books.xml, we can in fact use multiple sheets to run
XPath across different XML files.

When you select the result in the XPath evaluator you will see the appropriate XML element being
highlighted in the source window.

Author: Siva Prasanna Kumar.P

Blog: http://soa2world.blogspot.com/

Disclaimer: Author is not responsible for any unintended use of the above article or damages caused by
using the technologies mentioned in the article (if any).

Vous aimerez peut-être aussi