private NodeList getNodeListUsingJavaXPath ( String xpath ) throws Exception { XPathFactory xpathFac = XPathFactory . newInstance ( ) ; XPath theXpath = xpathFac . newXPath ( ) ; String html = getGUIDriver ( ) . getHtmlSource ( ) ; html = html . replaceAll ( ">\\s+<" , "><" ) ; InputStream input = new ByteArrayInputStream ( html . getBytes ( Charset . forName ( "UTF-8" ) ) ) ; XMLReader reader = new Parser ( ) ; reader . setFeature ( Parser . namespacesFeature , false ) ; Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; DOMResult result = new DOMResult ( ) ; transformer . transform ( new SAXSource ( reader , new InputSource ( input ) ) , result ) ; Node htmlNode = result . getNode ( ) ; // This code gets a Node from the // result. NodeList nodes = ( NodeList ) theXpath . evaluate ( xpath , htmlNode , XPathConstants . NODESET ) ; return nodes ; }
Get the list of nodes which satisfy the xpath expression passed in