How to implement siblings nodes (XPATH expressions) relation in Java using DOM and XALAN processor

53 Views Asked by At

Hello everyone I am developing a program in Java to read the XML using XPATH for siblings nodes (elements which are same level)

I am not able to implement below XPATH expression in Java:

//*:root/*:child1[.='child_value']/following-sibling::*:child2[*:subelement]/*:subelement3/*:subelement4/following-sibling::*:anyelement

Could any one please suggest any solution

1

There are 1 best solutions below

4
Michael Kay On BEST ANSWER

The construct *:root requires XPath 2.0, which isn't supported by Xalan. The simplest solution is to use Saxon instead.

In XPath 1.0 the way to select an element by local name alone is *[local-name()='root'] which gets a bit cumbersome for an expression like this that includes 7 such selections.