Java XPath Select selectNodes(String xpath, Object node)

Here you can find the source of selectNodes(String xpath, Object node)

Description

Select all children node of a xpath

License

Open Source License

Parameter

Parameter Description
xpath a parameter
node a parameter

Declaration

public static NodeList selectNodes(String xpath, Object node) 

Method Source Code

//package com.java2s;
/*//  w ww.j a  v  a 2  s  .  c o m
 * Movie Renamer
 * Copyright (C) 2014 Nicolas Magr?
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

import org.w3c.dom.NodeList;

public class Main {
    /**
     * Select all children node of a xpath
     *
     * @param xpath
     * @param node
     * @return
     */
    public static NodeList selectNodes(String xpath, Object node) {
        try {
            return (NodeList) getXPath(xpath).evaluate(node, XPathConstants.NODESET);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private static XPathExpression getXPath(String xpath) throws XPathExpressionException {
        return XPathFactory.newInstance().newXPath().compile(xpath);
    }
}

Related

  1. selectNodes(final Node node, final String xPath)
  2. selectNodes(Node nodeParent, String name)
  3. selectNodes(String express, Object source)
  4. selectNodes(String xPath, Node target)
  5. selectNodes(String xpath, Object node)
  6. selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression)
  7. selectNodeText(Node node, String expression)
  8. selectSingleElement(Element element, String xpathExpression)
  9. selectSingleNode(final Node node, final String xPath)