Created
February 28, 2014 17:48
-
-
Save fancellu/9275904 to your computer and use it in GitHub Desktop.
Fix for better control over XML output. Hope this little tip helps.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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