Java XPath Select selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression)

Here you can find the source of selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression)

Description

select Nodes Via X Path

License

Open Source License

Declaration

public static final List<Node> selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression)
            throws XPathExpressionException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing./*  w ww .  j av a 2s .  co  m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/

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 org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static final List<Node> selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression)
            throws XPathExpressionException {
        List<Node> data = new ArrayList<Node>();
        XPathExpression expression = xPath.compile(xPathExpression);
        Object result = expression.evaluate(startingNode, XPathConstants.NODESET);
        NodeList nodeList = (NodeList) result;
        for (int index = 0; index < nodeList.getLength(); index++) {
            data.add(nodeList.item(index));
        }
        return data;
    }
}

Related

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