Как обращаться к элементу по относительному пути GPATH

Как в GPATH обращаться к элементу по относительному пути, а не абсолютному?

Пробовал так:
$…element
…element
$.element

Не подходит. Может знает кто? В инете не нашел!

Вот тут еще не смотрели: http://www.groovy-lang.org/processing-xml.html#_gpath?

1 лайк

Смотрел конечно же. Там все примеры начинаются с корневого узла:
response.value.books

Как заюзать относительный путь то!? Без response.value?

Насколько я понимаю, в документации есть пример подобной ситуации.
http://groovy-lang.org/processing-xml.html#_speed_things_up_with_breadthfirst_and_depthfirst

what if we would like to look for a given value without having to know exactly where it is. Let’s say that the only thing we know is the id of the author “Lewis Carroll” . How are we going to be able to find that book?

def response = new XmlSlurper().parseText(books)

def bookId = response.'**'.find { book->
    book.author.text() == 'Lewis Carroll'
}.@id
2 лайка

Вот в Xpath все понятно, если ты хочешь обратиться к элементу по относительному пути ты просто делаешь так: //element

А тут как?

Да, что-то я тупанул.
В доке написано:

If you ever have used XPath you may have used expressions like

// : Look everywhere

/following-sibling::othernode : Look for a node “othernode” in the same level

More or less we have their counterparts in GPath with the methods breadthFirst() and depthFirst().