Java XPath: Get all the elements that match a query

江枫思渺然 提交于 2019-12-05 01:09:33

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
Jon Payne

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!