Here you can find the source of streamNodes(String xpath, Object node)
public static Stream<Node> streamNodes(String xpath, Object node)
//package com.java2s; //License from project: Open Source License import java.util.stream.IntStream; import java.util.stream.Stream; import javax.xml.namespace.QName; import javax.xml.xpath.XPathConstants; 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 Stream<Node> streamNodes(String xpath, Object node) { return stream((NodeList) evaluateXPath(xpath, node, XPathConstants.NODESET)); }//from ww w.j a va 2 s . c o m public static Stream<Node> stream(NodeList nodes) { return IntStream.range(0, nodes.getLength()).mapToObj(nodes::item); } public static Object evaluateXPath(String xpath, Object item, QName returnType) { try { return XPathFactory.newInstance().newXPath().compile(xpath).evaluate(item, returnType); } catch (XPathExpressionException e) { throw new IllegalArgumentException(e); } } }