Example usage for org.jdom2.xpath XPathBuilder setNamespaces

List of usage examples for org.jdom2.xpath XPathBuilder setNamespaces

Introduction

In this page you can find the example usage for org.jdom2.xpath XPathBuilder setNamespaces.

Prototype

public boolean setNamespaces(Collection<Namespace> namespaces) 

Source Link

Document

Add a number of namespaces to this XPathBuilder

Usage

From source file:com.c4om.utils.xmlutils.XMLLibsShortcuts.java

License:Apache License

/**
 * Simple method that performs a XPath query over elements
 * @param <T> The type of the XPath result.
 * @param path the path/*from w ww  . j ava2s.c o m*/
 * @param context a context node
 * @param filter an appropiate filter. Its type will be the one of the result
 * @param namespaces namespaces made available to XPath engine
 * @return the list of results
 */
public static <T> List<T> performJAXENXPath(String path, Object context, Filter<T> filter,
        Collection<Namespace> namespaces) {
    XPathBuilder<T> builder = new XPathBuilder<>(path, filter);
    if (namespaces != null) {
        builder.setNamespaces(namespaces);
    }
    XPathExpression<T> xpathExpression = builder.compileWith(XPATH_FACTORY);
    List<T> xpathResults = xpathExpression.evaluate(context);
    return xpathResults;
}