您好我想在
之前和之后添加根元素在
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
在
<pad>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
</pad>
答案 0 :(得分:2)
一种方法是使用StreamingMarkupBuilder
添加根节点。
def xml = """
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
"""
def nodes = new XmlSlurper().parseText(xml)
def markup = new groovy.xml.StreamingMarkupBuilder()
println markup.bind {
pad {
mkp.yield nodes
}
}