File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes How to go for  XPATH 2.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to go for  XPATH 2.0" Watch "How to go for  XPATH 2.0" New topic

How to go for XPATH 2.0

Anish Kuti

Joined: May 12, 2008
Posts: 29
Hi All,
I am using JDK1.5 and java XML parser (import javax.xml.*) for parsing my XML.Now while I am using
count(distinct-values(//tag/items/itemid)) ,my parser is getting failed. later I came to know this above type of XPATH is only supported by XPATH 2.0.

Can anyone let me know What I have to do to make my parser enable to parse the above type of xpath (supporting XPATH 2.0) ? Any change in code or any jar to be used!!

I am using the below java code to parse my XML
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource;

public class XmlParsing {

public void get() throws Throwable
String aa ="count(distinct-values(//tag/items/itemid))";
InputSource is = new InputSource("C://Users//kanis//Documents//office//Support//SMI_CHM6544.xml");
XPath xpath = XPathFactory.newInstance().newXPath();
String strArbitaryinfo= (String) xpath.evaluate(aa, is, XPathConstants.STRING);
System.out.println("------------------------Xml String ------------------\n"+strArbitaryinfo+"\n-----------------------------------------------------");

public static void main(String[] args) throws Throwable {
new XmlParsing().get();
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42954
Saxon ( implements XPath 2.0.
I agree. Here's the link:
subject: How to go for XPATH 2.0