Is there any way to generate XML using the literal syntax as such:
<a>
{
for (i <- Range(1, 3)) yield {
<b>{i}</b>
}
}
</a>
that will return
<a><b>1</b><b>2</b></a>
i.e. I want to use just a single compound statement which will somehow return the complete XML literal.
The only way I know is to do it in two steps: in the first step the for-yield statement will return IndexedSeq or something similiar which then in the second step I have to convert it to scala.xml.Elem. That’s OK, but I get the feeling that you can be more concise – nearly as concise as what I proposed in my code above.
Thanks.
What you posted works just fine…
If you want it to be more concise in terms of typing, you could use an inner statement of
So then you would just have this:
Which gives