What's the best way to wrap an XPath language/interface over POJOs?

1.5k views Asked by At

I'd like to expose a tree of POJOs via a simple "XPath" like language so that users can do something like /purchaseOrder/location[@city = 'Mountain View']?

2

There are 2 answers

0
Ashwin Jayaprakash On

I've looked at Apache JXpath which seems to be pretty decent and is somewhat maintained. I don't know how fast it is though.

I've also seen Jaxen which requires some extra work by the user as described here and by reading PMD's soure code. But Jaxen seems to have been abandoned by its authors. Also, I don't know what version of XPath is supported here.

Are there others?

3
bdoughan On

If your POJOs are mapped to XML via JAXB metadata, then you could wrap the root object in an instance of javax.xml.bind.util.JAXBSource and use the javax.xml.xpath APIs to issue XPath queries against it.