I have such a XML structure, with list of 'attachments', and I want iterate incoming List<String> files and create a groovy.util.Node for each of them and then return the builded Node. In code below I use only the fist element from list(base64 file), but I want to create attachments dynamically based on array size. I am new in groovy and can't find the way how to expand the Node properly.
import groovy.abi.XML
class TestService {
Node buildNode(List<String> files) {
Node node = XML.builder().
"sab:sendExternalEmail"("xmlns:sab": "http://sab/") {
"sab:to"('client@gmail.com')
"sab:subject"('Reply')
"sab:body"('Body')
"sab:from"('sender@gmail.com')
"sab:attachments"() {
"sab:attachment"() {
"sab:fileName"('file1')
"sab:fileBase64"(files[0])
}
}
}
}
}