Groovy XmlSlurper and inserting child nodes
Is it possible to use the Groovy's XMLSlurper and insert child nodes at an index?
Currently the GPathResult class has putAt(index) and appendNode(). The first replaces the element at the index rather than inserting and the second adds to the end.
I am tied to XmlSlurper rather than Xml开发者_如何学CParser unfortunately.
Thanks.
Found it. So simple (crazy awesome Groovy). All it takes is to add the node after the node in question using a closure and the + operator.
For example:
//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')
}
}
精彩评论