Freewind
Freewind

Reputation: 198388

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

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

Upvotes: 9

Views: 1069

Answers (3)

Alex Boisvert
Alex Boisvert

Reputation: 2918

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>

Upvotes: 6

Rob Stevenson-Leggett
Rob Stevenson-Leggett

Reputation: 35689

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>

Upvotes: 1

Nikolaus Gradwohl
Nikolaus Gradwohl

Reputation: 20134

you can escape the curly braces by doubling them

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

will give you

<name>{name}</name>

Upvotes: 17

Related Questions