Xml Literals
Viewing old version d7b45db5267a6141c956f00e214ffa4a92a1fed8; View Current
Scala supports XML literals. Meaning that this program:
outputs this:
This syntax can do more than just save you a few quotes and backslashes, however. You can use curly braces to dynamically insert expressions, as such:
Note how we don’t quote the title or href attributes; Scala knows that we are assigning XML attributes to dynamic variables (i.e. this isn’t just blind templating; it’s XML-aware). Also note how the quoted string we pass to the function gets escaped inside the attribute value.
Inside those curly braces, we can embed any Scala expression we want, so if we wanted to take a list and output it as a ul, this would work just fine:
Notice that inside our expression, we map our list of strings to a list of XML literals, themselves containing a dynamic expression.
Last Updated 07/25/2009 at 02:20:08 PM by davec
blog comments powered by Disqus
All Content by David Copeland is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.