public static List<Element> selectElements(XPathExpression expr,Node context){
  try {
    List<Element> elements=new ArrayList<Element>();
    NodeList result=(NodeList)expr.evaluate(context,XPathConstants.NODESET);
    for (int i=0; i < result.getLength(); i++) {
      Node item=result.item(i);
      if (item instanceof Element) {
        elements.add((Element)item);
      }
 else {
        throw new XmlException("Not an element: " + item);
      }
    }
    return elements;
  }
 catch (  XPathExpressionException e) {
    throw new XmlException(e);
  }
}

public static List < Element > selectElements ( XPathExpression expr , Node context ) { try { List < Element > elements = new ArrayList < Element > ( ) ; NodeList result = ( NodeList ) expr . evaluate ( context , XPathConstants . NODESET ) ; for ( int i = 0 ; i < result . getLength ( ) ; i ++ ) { Node item = result . item ( i ) ; if ( item instanceof Element ) { elements . add ( ( Element ) item ) ; } else { throw new XmlException ( "Not an element: " + item ) ; } } return elements ; } catch ( XPathExpressionException e ) { throw new XmlException ( e ) ; } }
evaluates the xpath expression to a list of elements .
