对于以下代码:
def writer = new StringWriter()
writer = new StreamingMarkupBuilder().bind {
Project(){MyTag('Help Me')}
}
println(writer.toString())
the output would be: <Project><MyTag>Help Me</MyTag></Project>
现在,如果我在上面的代码中有“MyTag('Help Me')”作为字符串 var 并想使用如下所示
def teststring = "MyTag('Help Me')"
def writer = new StringWriter()
writer = new StreamingMarkupBuilder().bind {
Project(){out<<teststring}
}
println(writer.toString())
the output am getting is: MyTag('Help Me')<Project></Project>
but am expecting: <Project><MyTag>Help Me</MyTag></Project>
是 groovy 的新手,有人帮助我正确实施或找到上述案例的错误吗?如果我必须使用 StreamingMarkupBuilder 和 XmlMarkupBuilder 以外的其他类,请告诉我?请注意,在我的实际场景中,文本变量实际上包含更多嵌套的子节点。