Java XPath Select selectNodeList(Node contextNode, String expression)

Here you can find the source of selectNodeList(Node contextNode, String expression)

Description

select Node List

License

LGPL

Declaration

public static NodeList selectNodeList(Node contextNode, String expression) throws XPathExpressionException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    private static XPathFactory xpathFactory;

    public static NodeList selectNodeList(Node contextNode, String expression) throws XPathExpressionException {
        XPath xpath = getXPathFactory().newXPath();
        XPathExpression xexpr = xpath.compile(expression);
        return (NodeList) xexpr.evaluate(contextNode, XPathConstants.NODESET);
    }//from w ww .j  a va  2 s .c  o m

    public static XPathFactory getXPathFactory() {
        if (xpathFactory == null) {
            xpathFactory = XPathFactory.newInstance();
        }
        return xpathFactory;
    }
}

Related

  1. getValueByXPathAsInt(Document document, String xpath)
  2. getValueFromXPath(Document document, String xpathString)
  3. getXmlElements(Document inXml, String xpath)
  4. selectElements(Element element, String xpathExpression)
  5. selectNodeIterator(Node nContextNode, String sXPath)
  6. selectNodeList(Node node, String expression)
  7. selectNodes(final Node node, final String xPath)
  8. selectNodes(Node nodeParent, String name)
  9. selectNodes(String express, Object source)