Search in sources :

Example 1 with XpathEngine

use of org.custommonkey.xmlunit.XpathEngine in project camel by apache.

the class Utils method evaluate.

/**
     * Evaluate an XPATH expression.
     *
     * @param xpath
     * @param xml
     * @return
     */
public static String evaluate(final String xpath, final String xml) {
    Map<String, Object> m = new HashMap<String, Object>();
    m.put("svrl", Constants.HTTP_PURL_OCLC_ORG_DSDL_SVRL);
    XpathEngine xpathEngine = XMLUnit.newXpathEngine();
    xpathEngine.setNamespaceContext(new SimpleNamespaceContext(m));
    try {
        return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml));
    } catch (Exception e) {
        LOG.error("Failed to apply xpath {} on xml {}", xpath, xml);
        throw new RuntimeCamelException(e);
    }
}
Also used : HashMap(java.util.HashMap) XpathEngine(org.custommonkey.xmlunit.XpathEngine) RuntimeCamelException(org.apache.camel.RuntimeCamelException) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Aggregations

HashMap (java.util.HashMap)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 SimpleNamespaceContext (org.custommonkey.xmlunit.SimpleNamespaceContext)1 XpathEngine (org.custommonkey.xmlunit.XpathEngine)1