XPath in Eclipse
XPath in Eclipse
in
Eclipse Galileo
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.
If you want to grasp the internal concepts on which XPath is dependent on then you have to read the
following specifications of W3C :
In the new project wizard select General -> Project and click “Next” and 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 ->
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.
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.
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).