「MarkupBuilder」を使うはずですが、わかりません。 import grails.converters.XML
を「XMLとして」行うことができるように見えますが、これは本当に私が欲しいものを与えているわけではありません。 Grailsを使ってXMLを作成するにはどうすればいいですか
<Thingie>
<someValue>blah</someValue>
<hellaItems>
<Item>
<anotherValue>yaddayadda</anotherValue>
</Item>
<Item>
<anotherValue>different from the first</anotherValue>
</Item>
</hellaItems>
</Thingie>
私もどこを開始するのか分からない...
私は動的にそれをしたい場合は@Stefan?私は一般的に "ビルダー"が問題かもしれないと私は理解していないと思う。
def items = ["yaddayadda","different from the first"]
更新:近づいているようですが、この最後の部分で私を助けることができます。私はこれをやっている:
def items = ["yaddayadda","different from the first"]
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.thingie() {
someValue('blah')
hellaItems(){
items.each{
item(){
anotherValue(it)
}
}
}
}
def xmlString = writer.toString()
println "maybe this will just work"
println xmlString
プリント:
maybe this will just work
<thingie>
<someValue>blah</someValue>
<hellaItems>
<item>
<anotherValue />
</item>
<item>
<anotherValue />
</item>
</hellaItems>
</thingie>
なぜそこに私のanotherValue
年代ではありませんか?
下記の "tmpHolder"を使用してUPDATE:SOLVEDされますが、Billはより良い構文の提案をしています。
def items = ["yaddayadda","different from the first"]
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.thingie() {
someValue('blah')
hellaItems(){
items.each{
def tmpHolder = it
item(){
anotherValue(tmpHolder)
}
}
}
}
def xmlString = writer.toString()
println "maybe this will just work"
println xmlString
あなたは近くですが、私は "それ"を使用しません。特にあなたが内部に別のクロージャーを持っているならば。 try items.each {txt - > item(){anotherValue(txt)}}? – billjamesdev
はい、これはtmpHolderよりずっと優れています。私はまだグルーヴを学んでいます。 – Mikey