java - 使用 REST 确保的 XmlPath 查找所有 XML 节点

标签 java rest rest-assured gpath

假设我有以下 XML 文档:

<Devices>
    <Scanners>
        <atom:link href="http://localhost/111" rel="http://1" />
        <atom:link href="http://localhost/222" rel="http://2" />
    </Scanners>
    <Printers>
        <atom:link href="http://localhost/333" rel="http://3" />
        <atom:link href="http://localhost/444" rel="http://4" />
    </Printers>
    <atom:link href="http://localhost/555" rel="http://5" />
</Devices>

使用 REST 放心的 XmlPath我想阅读全部 <atom:link>节点 - 实际上是它们的属性列表 - 放入列表中,无论节点位于树中的位置。到目前为止我的代码如下所示:

XmlPath xmlPath = new XmlPath(response);
// This gives me a list of five entries --> OK
List<Node> linkNodes = xmlPath.get("depthFirst().findAll { it.name() == 'link' }");
// This prints five empty lines --> NOT OK
for (Node linkNode : linkNodes) {
  System.out.println(linkNode.get("@href"));
}

我在这里缺少什么?

最佳答案

仅执行以下操作就足够了吗?

List<String> links = xmlPath.get("**.findAll { it.name() == 'link' }.@href");
...

关于java - 使用 REST 确保的 XmlPath 查找所有 XML 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28298851/

相关文章:

javascript - 如何加密 REST API 身份验证的密码

java - 高枕无忧:在数组中抓取 JSON 响应

java - Jayway Rest Assured Json 字符串转换路径

java - 尝试通过rest访问jpa数据时获取 "No mapping found for HTTP request with URI [/system/people]..."

java - 如何使用 SublimeLinter-javac 将 Gradle 托管依赖项添加到我的类路径?

java - Jersey Rest 服务何时实际启动/关闭?

json - 当对象名称中包含 DOT 时如何从 json 对象中检索字段值

java - 从文件中读取数字并检查随机生成

java - 如何从 SWIG 中的 C 指针生成 Java 数组

rest - 创建多个已具有 ID 的资源时的 PUT 与 POST