Groovy: Node.replaceNode with Node?

后端 未结 1 471
野的像风
野的像风 2021-01-16 09:25

Suppose I have a node I\'d like to replace with replaceNode, however, I don\'t want to use a Builder to do it - or rather, I already have the node

相关标签:
1条回答
  • 2021-01-16 09:59

    If you don't mind switching to XmlSlurper() the following should work:

    def top = new XmlSlurper().parse('input.xml')
    top.middle.each { node ->
        node.replaceNode {
            mkp.yield(new XmlSlurper().parse('replacement.xml')) 
        }   
    }
    

    Which will replace all middle nodes with the contents of replacement.xml

    0 讨论(0)
提交回复
热议问题