String buildAttrXPath ( String name , String ... value ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "//*[@" ) ; sb . append ( name ) ; if ( value . length == 1 ) { sb . append ( "='" ) ; sb . append ( value [ 0 ] ) ; sb . append ( "'" ) ; } sb . append ( "]" ) ; return sb . toString ( ) ; }
Build XPath expression for elements with attribute name and optional value .