Как получить следующего брата с помощью GPathResult

Как я могу получить следующего брата GPathResult? Например, у меня есть следующий код:

def priorityIssue = xmlReport.'**'.find { Issue ->
   Issue.Priority.text() == priority
}

Как мне получить следующего брата PriorityIssue?

Спасибо!


person jonatzin    schedule 15.04.2015    source источник
comment
Решит ли мой ответ проблему?   -  person Opal    schedule 16.04.2015


Ответы (1)


Более или менее это путь:

import groovy.util.XmlSlurper

def xml = new XmlSlurper().parseText('''
<issues>
    <issue>
        <id>1</id>
        <priority>1</priority>
    </issue>
    <issue>
        <id>2</id>
        <priority>2</priority>
    </issue>
</issues>
''')
def p = '1' 
def priorityIssue = xml.'**'.find { issue ->
    issue.priority.text() == p
}
def kids = priorityIssue.parent().children().list()
def idx = kids.indexOf(priorityIssue)
def sibling = kids[++idx]
assert sibling.id.text() == '2'
person Opal    schedule 15.04.2015
comment
Что касается Groovy 2.3.6, часть .list() является избыточной и приводит к ошибке времени выполнения. Аллес прекрасно и без этого. - person Pavel Vlasov; 13.11.2016
comment
@PavelVlasov без list(), остальная часть кода не работает, и это ответ на получение следующего брата или сестры. - person Pablo Pazos; 20.04.2018