class StubConfigXPathEvaluator {

    public Element getElementByXPath(final String expression, final Document document) {
        Element element = null;
        XPath xPath = xPathProvider.getXPath();
        try {
            nameSpaceProvider.setNameSpaceContext(xPath);
            XPathExpression expr = xPath.compile(expression);
            Node result = (Node) expr.evaluate(document, XPathConstants.NODE);
            if (result.getNodeType() == Node.ELEMENT_NODE) {
                element = (Element) result;
            }
        } catch (XPathExpressionException e) {
            throw new DescriptorCannotBeParsedException("Exception while trying to locate node in the stub configuration file", e);
        }
        return element;
    }

}