Java XPath Select selectNodes(String xPath, Node target)

Here you can find the source of selectNodes(String xPath, Node target)

Description

select Nodes

License

Open Source License

Declaration

public static NodeList selectNodes(String xPath, Node target) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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 {
    public static NodeList selectNodes(String xPath, Node target) {
        XPath xpathForUri = XPathFactory.newInstance().newXPath();
        NodeList nodes = null;//from w w  w  .j a  v a2  s . co  m

        try {
            XPathExpression expr = xpathForUri.compile(xPath);
            nodes = (NodeList) expr
                    .evaluate(target, XPathConstants.NODESET);
        } catch (XPathExpressionException e) {
            throw new RuntimeException(e);
        }

        return nodes;
    }
}

Related

  1. selectNodeList(Node contextNode, String expression)
  2. selectNodeList(Node node, String expression)
  3. selectNodes(final Node node, final String xPath)
  4. selectNodes(Node nodeParent, String name)
  5. selectNodes(String express, Object source)
  6. selectNodes(String xpath, Object node)
  7. selectNodes(String xpath, Object node)
  8. selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression)
  9. selectNodeText(Node node, String expression)