Java XPath: Get all the elements that match a query
You'll get a item of type NodeList
XPathExpression expr = xpath.compile("//Core.Reference");NodeList list= (NodeList) expr.evaluate(doc, XPathConstants.NODESET);for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); System.out.println(node.getTextContent()); // work with node
See How to read XML using XPath in Java
As per that example, If you first compile the XPath expression then execute it, specifying that you want a NodeSet back you should get the result you want.