目前我仅获得第一个信誉 > 100 的 DisplayName。如何打印第 10 个 DisplayName? 就像输出一样,我想获取信誉度 > 100 的前 10 个 DisplayName 的列表。
这是我的主文件:
String output = (String) xPath.evaluate(
"/users/row[@Reputation>'100']/@DisplayName",
doc2.getDocumentElement(),
XPathConstants.STRING);
System.out.println("DisplayName for user with Reputation > 100: " + output);
最佳答案
尝试 position()
语法
/users/row[@Reputation>'100' and position() < 11]/@DisplayName
根据Xpath Syntax :
/bookstore/book[position()<3]
Selects the first two book elements that are children of the bookstore element
关于java - 如何打印XML中前十个数据的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50875591/