A Scala XML EntityRef example (unicode character)

This page shows a good Scala XML EntityRef example:

import scala.xml._
val xml = <body>Hello{EntityRef("#8198")}World</body>

That page states that 8198 is the unicode value for a tiny space character.

That code isn't too helpful unless you can see it in the REPL, so here it is:

scala> import scala.xml._
import scala.xml._

scala> val xml = <body>Hello{EntityRef("#8198")}World</body>
xml: scala.xml.Elem = <body>Hello&#8198;World</body>

scala> xml.text
res0: String = Hello World

As you can see, EntityRef converts the #8198 value it's given into the output value &#8198;.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.