Here you can find the source of selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression)
public static final List<Node> selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression) throws XPathExpressionException
//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; } }