JXPath is a java library for Object Graph Navigation using the XPath syntax.
This requires the libraries commons-jxpath-1.3.jar, commons-beanutils.jar and commons-logging.jar to be in classpath.
The following example shows accessing extension function as predicate in JXPath.
//Create JXPathContext with ComplexBean instance as ROOT node
JXPathContext context = JXPathContext.newContext(bean);
//Register a class function in the name space 'index'
context.setFunctions(new ClassFunctions(IndexFunction.class, "index"));
//Get elements at ODD index
Iterator<?> oddVals = context.iterate("/stringList[index:odd()]"); while (oddVals.hasNext()) {
System.out.println(oddVals.next());
}
//Get elements at EVEN index
Iterator<?> evenVals = context.iterate("/stringList[index:even()]"); while (evenVals.hasNext()) {
System.out.println(evenVals.next());
}
}