How to find element by attribute value in GPath?

yegor256 picture yegor256 · Aug 11, 2011 · Viewed 22.4k times · Source

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

Answer

Nicolas Modrzyk picture Nicolas Modrzyk · Aug 11, 2011

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: