XmlUtil { public static Node findNode(Node document, String xPathExpression) throws ProblemException { try { XPath xpath = XPathFactory.newInstance().newXPath(); Node node = (Node) xpath.evaluate(xPathExpression, document, XPathConstants.NODE); return node; } catch (XPathExpressionException e) { logger.error(e.toString(), e); throw new ProblemException(e, XmlProblem.XPATH, e.toString()); } }  static Document createDom(); static Document createDOMDocument(String xml); static String prettyFormatXml(String xml, String encoding); static String domToString(Node node, String encoding, boolean pretty); static Node findNode(Node document, String xPathExpression); static Element getFirstElement(Node node); static boolean containsElements(NodeList nodeList); static XMLGregorianCalendar newXMLGregorianCalendar(Date date); static T unmarshal(Class<T> targetClass, String xml); static String marshal(T object); static Source getSource(String xml);  }
@Test public void testFindNode() throws Exception { Node found = XmlUtil.findNode(DOCUMENT, "/root/elem"); assertEquals("elem", found.getNodeName()); try { XmlUtil.findNode(DOCUMENT, "Strč prst skrz krk"); fail(); } catch (ProblemException expected) { } }