How to find element by attribute value in GPath?

后端 未结 4 1404
故里飘歌
故里飘歌 2021-02-18 18:35

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

4条回答
  •  梦谈多话
    2021-02-18 18:45

    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

提交回复
热议问题