Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output {name} in xml of scala, not convert it?

Tags:

xml

scala

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}?

like image 802
Freewind Avatar asked Jul 26 '10 16:07

Freewind


3 Answers

you can escape the curly braces by doubling them

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

will give you

<name>{name}</name>
like image 149
Nikolaus Gradwohl Avatar answered Oct 24 '22 05:10

Nikolaus Gradwohl


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>
like image 30
Alex Boisvert Avatar answered Oct 24 '22 04:10

Alex Boisvert


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>
like image 21
Rob Stevenson-Leggett Avatar answered Oct 24 '22 03:10

Rob Stevenson-Leggett