/** * Queries a string via the given XPath. All contained XML is converted to a * string. * * @param path the xpath used to retrieve the xml sub tree * @return a string representing the xml sub-tree returned by the given xpath expression * @throws IllegalArgumentException if an invalid xpath was given */ @Nullable public String queryXMLString(String path) { try { XPath xpath = XPATH.newXPath(); Object result = xpath.evaluate(path, node, XPathConstants.NODE); if (result == null) { return null; } if (result instanceof Node) { return serializeNodeAsXML((Node) result); } return result.toString().trim(); } catch (XPathExpressionException e) { throw new IllegalArgumentException(e); } }