static final String xpath ( Element element ) { StringBuilder sb = new StringBuilder ( ) ; Node iterator = element ; while ( iterator . getNodeType ( ) == Node . ELEMENT_NODE ) { sb . insert ( 0 , "]" ) ; sb . insert ( 0 , siblingIndex ( ( Element ) iterator ) + 1 ) ; sb . insert ( 0 , "[" ) ; sb . insert ( 0 , ( ( Element ) iterator ) . getTagName ( ) ) ; sb . insert ( 0 , "/" ) ; iterator = iterator . getParentNode ( ) ; } return sb . toString ( ) ; }
Return an XPath expression describing an element