gpt4 book ai didi

xml - 如何使用 GPathResult 获取下一个 sibling

转载 作者:数据小太阳 更新时间:2023-10-29 02:26:14 28 4
gpt4 key购买 nike

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

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

如何获得 priorityIssue 的下一个同级?

谢谢!

最佳答案

或多或少这是要走的路:

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'

关于xml - 如何使用 GPathResult 获取下一个 sibling ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29652995/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com