/** * Evaluate a string XPath expression against the retrieved document. * An XPath expression can return a Node or subinterface such as * Element or Text, a NodeList, or a Boolean, Number, or String value. * @param xpathExpression the XPath expression as a string * @param as the type of the value * @return the value produced by the XPath expression */ public <T> T evaluateXPath(String xpathExpression, Class<T> as) throws XPathExpressionException { return evaluateXPath(xpathExpression, get(), as); } /**
/** * Evaluate a compiled XPath expression against the retrieved document. * An XPath expression can return a Node or subinterface such as * Element or Text, a NodeList, or a Boolean, Number, or String value. * @param xpathExpression an XPath expression compiled previously * @param as the type of the value * @return the value produced by the XPath expression */ public <T> T evaluateXPath(XPathExpression xpathExpression, Class<T> as) throws XPathExpressionException { return evaluateXPath(xpathExpression, get(), as); } /**
/** * Evaluate a compiled XPath expression against the retrieved document. * An XPath expression can return a Node or subinterface such as * Element or Text, a NodeList, or a Boolean, Number, or String value. * @param xpathExpression an XPath expression compiled previously * @param as the type expected to be matched by the xpath * @param <T> the type to return * @return the value produced by the XPath expression * @throws XPathExpressionException if xpathExpression cannot be evaluated */ public <T> T evaluateXPath(XPathExpression xpathExpression, Class<T> as) throws XPathExpressionException { return evaluateXPath(xpathExpression, get(), as); } /**
/** * Evaluate a string XPath expression against the retrieved document. * An XPath expression can return a Node or subinterface such as * Element or Text, a NodeList, or a Boolean, Number, or String value. * @param xpathExpression the XPath expression as a string * @param as the type expected to be matched by the xpath * @param <T> the type to return * @return the value produced by the XPath expression * @throws XPathExpressionException if xpathExpression cannot be evaluated */ public <T> T evaluateXPath(String xpathExpression, Class<T> as) throws XPathExpressionException { return evaluateXPath(xpathExpression, get(), as); } /**
private void checkXMLDocRows(RowSet<DOMHandle> rowSet) throws XPathExpressionException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, SAXException, IOException { int rowCount = 0; for (DOMHandle xmlRow: rowSet) { xmlRow = initNamespaces(xmlRow); NodeList row = xmlRow.evaluateXPath("/table:row/table:cell", NodeList.class); rowCount++; assertEquals("unexpected column count in XML", 3, row.getLength()); Element testElement = (Element) row.item(0); assertEquals("unexpected first binding name in XML", "rowNum", testElement.getAttribute("name")); assertEquals("unexpected first binding value in XML", String.valueOf(rowCount), testElement.getTextContent()); testElement = (Element) row.item(1); assertEquals("unexpected second binding name in XML", "uri", testElement.getAttribute("name")); assertEquals("unexpected second binding value in XML", uris[rowCount - 1], testElement.getTextContent()); testElement = (Element) row.item(2); assertEquals("unexpected third binding name in XML", "doc", testElement.getAttribute("name")); if (uris[rowCount - 1].endsWith(".xml")) { assertXMLEqual("unexpected third binding value in XML", docs[rowCount - 1], nodeToString(testElement.getElementsByTagName("a").item(0)) ); } else { assertEquals("unexpected third binding value in XML", docs[rowCount - 1], testElement.getTextContent()); } } assertEquals("row count for XML document join", 3, rowCount); } private void checkJSONDocRows(RowSet<JacksonHandle> rowSet) {
String total = responseHandle.evaluateXPath("string(/search:response/@total)", String.class); assertNotNull("null total", total); NodeList resultList = responseHandle.evaluateXPath(resultsExpression, NodeList.class); assertNotNull("null result list", resultList); assertEquals("result count mismatch", resultList.getLength(), Integer.parseInt(total)); Element firstResult = responseHandle.evaluateXPath("/search:response/search:result[1]", Element.class); assertNotNull("null first result", firstResult); String firstResultUri = responseHandle.evaluateXPath("string(@uri)", firstResult, String.class); String firstItemUri = ((Element) resultList.item(0)).getAttribute("uri"); assertEquals("first uri mismatch", firstResultUri, firstItemUri);
NodeList testList = domHandle.evaluateXPath("/table:table/table:columns/table:column", NodeList.class); assertEquals("unexpected header count in XML", 2, testList.getLength()); Element testElement = (Element) testList.item(0); testList = domHandle.evaluateXPath("/table:table/table:rows/table:row", NodeList.class); assertEquals("unexpected row count in XML", 1, testList.getLength()); testList = domHandle.evaluateXPath("/table:table/table:rows/table:row[1]/table:cell", NodeList.class); checkSingleRow(testList, datatypeStyle);
assertTrue("no XML row to iterate", xmlRowItr.hasNext()); DOMHandle xmlRow = initNamespaces(xmlRowItr.next()); checkSingleRow(xmlRow.evaluateXPath("/table:row/table:cell", NodeList.class), datatypeStyle); assertFalse("expected one XML row", xmlRowItr.hasNext()); assertTrue("no XML rows as to iterate", xmlRowItrAs.hasNext()); DOMHandle xmlRow = initNamespaces(new DOMHandle().with(xmlRowItrAs.next())); checkSingleRow(xmlRow.evaluateXPath("/table:row/table:cell", NodeList.class), datatypeStyle); assertFalse("expected one XML row", xmlRowItrAs.hasNext());