XPath is a query language designed for querying XML documents. For example, a simple XPath query that finds the titles of all the books in a document whose author is Sandeep JOshi might look like this:

//book[author="Sandeep Joshi"]/title

it is possible to integrate XPath into Java programs so that you get the best of both worlds: Java for what Java is good for and XPath for what XPath is good for.Java 5 introduced the javax.xml.xpath package to provide an engine and object-model independent XPath library.

Next you create an XPathFactory:

XPathFactory factory = XPathFactory.newInstance();

You then use this factory to create an XPath object:

XPath xpath = factory.newXPath();


The XPath object compiles the XPath expression:

XPathExpression expr = xpath.compile("//book[author="Sandeep Joshi"]/title");

Advantages of using XPATH:

1). XPath is simple to use and more effective then the conventional XML mining programs.

2). XPATH can be used in XSLT, Java.

3). XPATH offers wide range of patterns to choose from

4). Vast number of online resources are available for XPATH. Some are:

www.w3schools.com/Xpath

www.ibm.com/developerworks/library/x-javaxpathapi.html

 




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)