Java XPath Get getNodes(Node node, String expStr)

Here you can find the source of getNodes(Node node, String expStr)

Description

get Nodes

License

BSD License

Declaration

private static List<Node> getNodes(Node node, String expStr) throws XPathExpressionException 

Method Source Code

//package com.java2s;
/**//from  w  ww.j  a v  a2  s . c om
 * Copyright 5AM Solutions Inc
 * Copyright SemanticBits LLC
 * Copyright AgileX Technologies, Inc
 * Copyright Ekagra Software Technologies Ltd
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/cacis/LICENSE.txt for details.
 */

import java.util.ArrayList;
import java.util.List;

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 List<Node> getNodes(Node node, String expStr) throws XPathExpressionException {
        final List<Node> nodes = new ArrayList<Node>();
        final XPathFactory fac = XPathFactory.newInstance();
        final XPath xpath = fac.newXPath();
        final XPathExpression exp = xpath.compile(expStr);
        final NodeList nl = (NodeList) exp.evaluate(node, XPathConstants.NODESET);
        for (int i = 0; i < nl.getLength(); i++) {
            nodes.add(nl.item(i));
        }
        return nodes;
    }
}

Related

  1. getNodeList(Node node, String xpath)
  2. getNodeList(Node xmlNode, String xpathString)
  3. getNodeList(Reader reader, String expression)
  4. getNodeListAsArray(Node doc, String xpath)
  5. getNodeListAttValAsStringCol(final String xPath, final Node node, final String attrName)
  6. getNodesByPath(String path, Element localElement, Document doc)
  7. getNodesByXPath(Document doc, XPathExpression expr)
  8. getNodesByXPath(Element parent, String name)
  9. getNodesListXpathNode(final String xPath, final Node node)