是否可以使用Groovy的XMLSlurper并在索引处插入子节点?
目前,GPathResult类具有putAt(index)和appendNode().第一个替换索引处的元素而不是插入,第二个添加到结尾.
不幸的是,我与XmlSlurper而不是XmlParser联系在一起.
谢谢.
Dam*_*amo 16
找到了.如此简单(疯狂的令人敬畏的 Groovy).所需要的是使用闭包和+运算符在相关节点之后添加节点.
例如:
//Add the ac:MessageStatus after ac:MessageDateTime (this is an Acord message hence the ac:)
root.'ac:MessageDateTime' + {
'ac:MessageStatus' {
'ac:MessageStatusCode'('ac:Success')
'ac:SuccessCode'('ac:Success')
}
}
Run Code Online (Sandbox Code Playgroud)