tags:

views:

62

answers:

3
val name = "mike"
val xml = <name>{name}</name>

xml will be <name>mike</name>

But what if I want the xml be <name>{name}</name>, not convert the {name}?

+10  A: 

you can escape the curly braces by doubling them

val xml = <name>{{name}}</name>

will give you

<name>{name}</name>
Nikolaus Gradwohl
+1  A: 

Sounds like you need to use the xml entities for { } and not { } themselves.

For example:

val name = "mike"
val xml = <name>&#123;name&#125;</name>
Rob Stevenson-Leggett
+4  A: 

To complement other answers, you can also provide a Text node inside your XML literal:

import scala.xml.Text

<xml> {
  Text("{foo}")
} </xml>

will produce,

<xml> {foo} </xml>
Alex Boisvert