java - 如何打印XML中前十个数据的列表

标签 java parsing xpath

目前我仅获得第一个信誉 > 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/

相关文章:

iphone - Objective-C JSON 解析错误

html - selenium Web Driver不能点击DIV元素是真的吗?

Java xPath - 从 XML 中提取子文档

java - Spring HandlerInterceptorAdapter postHandle 有保证吗?

java - 如何使用 clp-java 解决简单的线性问题

java - 无法使用 java 1.8 更新 docker 容器

javascript - 如何根据语言环境将字符串转换为数字(与 .toLocaleString 相反)?

c++ - 将 C++ 方法声明从 .hh 文件移动到 .cc 文件

sql-server - SQL Server XML查询: Query multiple child elements with same name

java - 部署期间出现 ClassNotFound 异常