爲下面的代碼:內StreamingMarkupBuilder()使用字符串變量綁定{}在Groovy
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(‘幫我’)」在上面的代碼作爲一個字符串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>
是新來的常規使用,任何人幫我正確執行或找到上述情況的錯誤呢?請讓我知道如果我不得不使用StreamingMarkupBuilder和XmlMarkupBuilder以外的其他類嗎? 請注意,在我的實際場景中,文本變量實際上包含更多嵌套的子節點。
在此先感謝。 –