0

使用来自 SO 和 codehaus 的许多帮助文章和案例,我写了如下内容:

import groovy.xml.MarkupBuilder
def EUIDroster = context.expand(here goes some data like '[123000,123001]' )

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)

builder() {
    EUIDList(){
        for (e in EUIDroster){EUID(e)}
    }
}

EUIDList.println()

我的目标是制作一个结构如下的 xml 文件:

<EUID>123001</EUID>
<EUID>123002</EUID>

我做错了什么?

4

1 回答 1

2

试试这个:

import groovy.xml.MarkupBuilder

def EUIDroster = [123000,123001]
def writer = new StringWriter()
new MarkupBuilder( writer ).EUIDList {
    EUIDroster.each { e ->
        EUID( e )
    }
}
println writer.toString()

那应该打印:

<EUIDList>
  <EUID>123000</EUID>
  <EUID>123001</EUID>
</EUIDList>
于 2013-08-29T08:30:42.790 回答