Skip to content
Aaron S. Hawley edited this page Jan 26, 2019 · 6 revisions

These are frequently asked questions about the Scala XML library that aren't already in the Introduction to Scala XML and the Getting started guide.

How long has Scala supported XML?

From the beginning, Scala has supported XML literals, pattern matching and queries as early as 2004 to 2006 in the 1.x series of Scala.

How long has the XML library been separate from the compiler?

Since version 2.11.0 of the Scala compiler, the Scala XML library has been developed and published separately from the compiler.

Why is the XML library no longer part of the compiler?

To make the compiler less monolithic and more modular, various components that had been developed alongside the compiler were separated out for 2.11 and called "modules". This included the XML library, but also included the Scala Swing, Scala continuations and Scala parser combinators. At the time, making them optional modules helped reduce the size of the Scala library's JAR file by 20%.

Why does the Scala compiler still depend on the Scala XML library?

The Scaladoc feature in the compiler still requires the Scala XML library, even though it is developed and published separately.

In Scala 2.12 and earlier, regardless of whether you included scala-xml as a dependency or not, you could use scala-xml from the console in sbt. This was fixed in Scala 2.13, but was also fixed in sbt 1.1.2 and later for all version of Scala (2.11 and later).

Can I use a different version of Scala XML from the Scala compiler?

Yes, a library or any Scala program can use a different version of Scala XML from the version that the Scala compiler depends on.

As of September 2018, all versions of scala-xml up to 1.1.1 is still source-compatible to the scala-xml that shipped with Scala 2.11. The compiler doesn't bother changing its version of scala-xml after the first release in the major version series. Scala 2.11 depends on 1.0.5, but you can use a later version. Scala 2.12 depends on 1.0.6, but you can use a later (or earlier) version.

| Scala compiler | scala-xml | |----------------+---------------| | 2.10 | included | | 2.11 | 1.0.5 | | 2.12 | 1.0.6 | | 2.13 | removed |

What will be changing for XML in Scala 3 (code named "Dotty")?

As of July 2018, Scala 3 will plan to provide XML string interpolation via a scala-xml-quote module.

Will Scala 3 (code named "Dotty") support XML literals?

No, to simplify the Scala parser and compiler and the Scala language specification, the XML literal support will be dropped in Scala 3. As of July 2018, XML literals are still not removed from the Dotty code base, though.

What will happen with scala-xml in Scala 3 ("Dotty")?

There won't be a way for scala-xml to provide XML literal "support" in Scala 3.x. The proposed XML string interpolation will be an optional module in Scala 3.x to provide type checked XML strings as an alternative to XML literals in Scala 2.

As of July 2018, the XML string interpolation module still has a dependency on the scala-xml library. As of July 2018, the scala-xml library is still a direct dependency in the Dotty compiler code base, as well, but the plan is to rip it out soon.

What parts of the Scala ecosystem depend on XML literals?

As of July 2018, the following Scala-based projects depend on XML literals.

  1. Scala compiler test suite
  2. Scala 3 compiler ("dotty") test suite
  3. Scala compiler scaladoc (dropped in 2.13.0-M4)
  4. Scala compiler build.sbt
  5. The Scala XML test suite
  6. pomExtra in sbt configuration
  7. XML responses in Play Framework
  8. XML responses in Lift Framework
  9. Spark XML test suite
  10. Akka HTTP test suite
  11. Scalatest test suite
  12. scalaxb test suite
  13. scoverage plugin
  14. Intellij sbt plugin test suite
  15. Binding.scala by ThoughtWorks, Inc.
  16. scalajs-react support for JSX
  17. Twirl (uses string interpolation?)
  18. monadic-html (only for Scala.js)
  19. validation-xml test suite
  20. XML responses in http4s
  21. Apache daffodil test suite
  22. scala-xml-diff test suite
  23. xs4s test suite
  24. yaidom test suite
  25. xmlrpc for Scala test suite
  26. xtract test suite
  27. xml-lens (doesn't use literals?)

What are popular use cases for XML literal support?

It is common to write Scala code that can interact with XML files or XML data without literals. Here are some examples of using XML literals in Scala code.

  1. XML protocols (eg. SOAP, HTTP requests and responses, ...)
  2. HTML templating
  3. XML templating
  4. JSX syntax in React.js
  5. Setting Maven-style pom.xml settings
Clone this wiki locally