Example usage for javax.xml.xpath XPath setNamespaceContext

List of usage examples for javax.xml.xpath XPath setNamespaceContext

Introduction

In this page you can find the example usage for javax.xml.xpath XPath setNamespaceContext.

Prototype

public void setNamespaceContext(NamespaceContext nsContext);

Source Link

Document

Establish a namespace context.

Usage

From source file:smartrics.rest.fitnesse.fixture.support.Tools.java

public static XPathExpression toExpression(Map<String, String> ns, String xpathExpression) {
    try {//from w w  w. j  a v a 2s .c  o  m
        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();
        if (ns.size() > 0) {
            xpath.setNamespaceContext(toNsContext(ns));
        }
        XPathExpression expr = xpath.compile(xpathExpression);
        return expr;
    } catch (XPathExpressionException e) {
        throw new IllegalArgumentException("xPath expression can not be compiled: " + xpathExpression, e);
    }
}