Scala support for Inline XML

Scala supports defining inline XML, a bit like PHP does. It features string interpolation but using just braces – no dollar signs.

Example:

object Movies extends App {
  val title="Goodfellas"
  val genre="Gangster"
  val movie = <movie genre={genre}><title>{title}</title></movie>
  println("movie = " + movie)
}

output:

movie = <movie genre="Gangster"><title>Goodfellas</title></movie>

The resulting var is a scala.xml.Elem

Advertisements

One thought on “Scala support for Inline XML

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s