September 2015
Intermediate to advanced
250 pages
6h 40m
English
Scala treats XML as a first-class citizen. So, instead of embedding XML documents into strings, you can place them inline in your code like you’d place an int or a Double value. Let’s take a look at an example:
| UsingScala/UseXML.scala | |
| | val xmlFragment = |
| | <symbols> |
| | <symbol ticker="AAPL"><units>200</units></symbol> |
| | <symbol ticker="IBM"><units>215</units></symbol> |
| | </symbols> |
| | |
| | println(xmlFragment) |
| | println(xmlFragment.getClass) |
We created a val named xmlFragment and directly assigned it to a sample XML content. Scala parsed the XML content and happily created an instance of scala.xml.Elem, as you see in the output:
| | <symbols> |
| | <symbol ticker="AAPL"><units>200</units></symbol> |
| | <symbol ticker="IBM"><units>215</units></symbol> ... |
Read now
Unlock full access