gpt4 book ai didi

xml - 如何访问父 XML 元素

转载 作者:数据小太阳 更新时间:2023-10-29 03:00:32 24 4
gpt4 key购买 nike

我正在像这样迭代一个 XML 文件:

new XmlSlurper().parseText(getServiceConfigXml())
.'**'
.findAll { it.name() == 'something' }
.each { node ->

println "attribute: ${node.attributes()} and body: ${node.text()}"
}

如何访问“节点”的父元素?

最佳答案

${node.parent().attributes()}

你甚至可以做到

${node.parent().parent().attributes()}

访问父节点的父节点

关于xml - 如何访问父 XML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43800278/

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