Java tutorial
//package com.java2s; 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 { static XPath xpath = XPathFactory.newInstance().newXPath(); public static List<String> getValueList(Node node, String exprStr) throws XPathExpressionException { ArrayList<String> r = new ArrayList<>(); XPathExpression expr = xpath.compile(exprStr); NodeList nodes = (NodeList) expr.evaluate(node, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { r.add(nodes.item(i).getNodeValue()); } return r; } }