XMLUtils { public static Node createNodeUsingXPathExpression(String expression, String xml) throws XPathExpressionException, UnsupportedEncodingException { return (Node) XMLUtils.createXPathExpression(expression).evaluate(new InputSource(new ByteArrayInputStream(xml.getBytes("utf-8"))), XPathConstants.NODE); } private  XMLUtils(); static String transformXML(final InputStream xml, final InputStream xslt); static String createPrettyXML(Document document); static XPathExpression createXPathExpression(final String expression); static Boolean createBooleanUsingXPathExpression(String expression, String xml); static NodeList createNodeListUsingXPathExpression(String expression, String xml); static Node createNodeUsingXPathExpression(String expression, String xml);  }
@Test public void createNodeUsingXPathExpressionTest() throws XPathExpressionException, UnsupportedEncodingException { Node result = XMLUtils.createNodeUsingXPathExpression("/parentNode/childNode[1]", testXml); assertThat(result.getTextContent(), equalTo("1")); result = XMLUtils.createNodeUsingXPathExpression("/parentNode/childNode[2]", testXml); assertThat(result.getTextContent(), equalTo("2")); }