Skip to content

Instantly share code, notes, and snippets.

@fancellu
Created February 28, 2014 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fancellu/9275904 to your computer and use it in GitHub Desktop.
Save fancellu/9275904 to your computer and use it in GitHub Desktop.
Fix for better control over XML output. Hope this little tip helps.
First we emit nodes, but they are all joined up
<that>x</that><that>x</that><that>x</that><that>x</that>
Then attempt to inject CR after end of "that". But only injects CR after "x"
<that>
</that><that>x
</that><that>x
</that><that>x
</that>
Then we try to put a Text("\n") node at the end, but instead get 4 CRs. This is because the value of the yield expression
is the last value, the Text node.
<CR/>
<CR/>
<CR/>
<CR/>
Then we do it properly using a Seq of Nodes with Text, and it works ok
<that>x</that>
<that>x</that>
<that>x</that>
<that>x</that>
val that= <that>x</that>
val thatcr= Seq(that,Text("\n"))
val xml= <root>
{ for (x<-1 to 4) yield that }
{ for (x<-1 to 4) yield
<that>x
</that>
}
{ for (x<-1 to 4) yield
<that>x
</that>
Text("\n")
}
{ for (x<-1 to 4) yield thatcr }
</root>
println(xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment