class XMLUtil extends AbstractCaller {

    @Description("Returns a object by xpath.<br>" +
            "<b>content</b> - xml document<br>" +
            "<b>xpath</b> - path to object<br>" +
            "Example:<br/>" +
            "#{getObjectByXPath(content, xpath)}")
    @UtilityMethod
    public Map<String, ?> getObjectByXPath(String content, String xpath) {
        NodeList nodes = getNodesByXPath(content, xpath);

        if (nodes.getLength() == 0) {
            return Collections.emptyMap();
        }
        if (nodes.getLength() != 1) {
            throw new EPSCommonException("There are several nodes for this xpath \"" + xpath + "\".");
        }
        if (hasOnlyTextNode(nodes.item(0))) {
            throw new EPSCommonException("Node isn't object.");
        }

        return nodeToMap(nodes.item(0));
    }

}