tags:

views:

82

answers:

1

Hi,

I need to generate some kind of a nested Xpath on runtime. Do you know of any Java lib or helper, which can assist with the creation of a complex Xpath expression ? It need it to support nesting, AND, OR and simple operators like equal and contains.

Here is an example of an expression I need to build at runtime (The number of 'Policy' element may vary - it depends on the user input)

//Root[ Policy [ Report/Name/text() = 'report #1' ][ Policy [ Report/Name/text() = 'report #2' ]

Thanks.

A: 

This is a little tricky. You many want to look at the Jaxen project, as it has built in parsers for creating XPath objects from their string representations. You may be able to dig through the parser code and figure out how to construct and XPath object directly without needing to call the parser - from the looks of it I'd recommend starting with the JaxenHandler class.

toluju