如何在GPath中查找按属性值的元素? [英] How to find element by attribute value in GPath?

查看:148
本文介绍了如何在GPath中查找按属性值的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GPath中,这个XPath的替代方案 // div [@ id ='foo'] >是什么?一般情况下,我可以在哪里找到这个文档?

What is an alternative to this XPath //div[@id='foo'] in GPath? In general, where I can find this documentation?

推荐答案

以下是相应的代码片段:

Here is the corresponding snippet:

def node = new XmlSlurper().parseText(...)
def foo = node.depthFirst().findAll { it.name() == 'div' && it.@id == 'foo'}

您可能想阅读的其他一些链接:

A few other links you may want to read:

  • GPath documentation
  • Processing XML with Groovy

这篇关于如何在GPath中查找按属性值的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆