4

如何获得 GPathResult 的下一个兄弟?例如我有以下代码:

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

如何获得 priorityIssue 的下一个兄弟姐妹?

谢谢!

4

1 回答 1

5

或多或少这是要走的路:

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'
于 2015-04-15T16:30:54.427 回答