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 nested properties in JXPath.
/**
* @param args
*/ public static void main(String[] args) {
BookStore bookStore = new BookStore(
Arrays.asList( new Book("A1", 11.11, new Author("X1")), new Book("B2", 22.22, new Author("X2")), new Book("C3", 33.33, new Author("X3")), new Book("D4", 44.44, new Author("X4"))
)
);
//Create JXPathContext with BookStore instance as ROOT node
JXPathContext context = JXPathContext.newContext(bookStore);
//Get the book with title 'B2'
System.out.println(context.getValue("/books[@title='B2']"));
//Get the price of book with title 'B2'
System.out.println(context.getValue("/books[@title='B2']/price"));
//Get the author name of book titled 'B2'
System.out.println(context.getValue("/books[@title='B2']/author/name"));
//Get the author email of book titled 'B2'
System.out.println(context.getValue("/books[@title='B2']/author/email"));
}