import groovy.xml.MarkupBuilder
def ids = [1111, 2222, 3333]
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.person() {
ids.collect { id ->
user() {
userid(id)
}
}
}
print(writer.toString())