-
Notifications
You must be signed in to change notification settings - Fork 92
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.
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.
Since version 2.11.0 of the Scala compiler, the Scala XML library has been developed and published separately from 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%.
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).
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 May 2019, all versions of scala-xml up to 1.2.0 are 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 |
As of May 2019, Scala 3 will provide support for XML literals, but they will be deprecated. Dotty plans to provide XML string interpolation via a scala-xml-quote module.
No, to simplify the Scala parser and compiler and the Scala language specification, the XML literal support will eventually be dropped in Scala 3. As of May 2019, XML literals are still not removed from the Dotty code base, though.
There will be a way for scala-xml to provide XML literals 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.
As of May 2019, the XML string interpolation module still has a dependency on the scala-xml library. As of May 2019, 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.
As of May 2019, the following Scala-based projects depend on XML literals.
- Scala compiler test suite
- Scala 3 compiler ("dotty") test suite
- Scala compiler scaladoc (dropped in 2.13.0-M4)
- Scala compiler build.sbt
- The Scala XML test suite
-
pomExtra
in sbt configuration - XML responses in Play Framework
- XML responses in Lift Framework
- Spark XML test suite
- Akka HTTP test suite
- Scalatest test suite
- scalaxb test suite
- scoverage plugin
- Intellij sbt plugin test suite
- Binding.scala by ThoughtWorks, Inc.
- scalajs-react support for JSX
- Twirl (uses string interpolation?)
- monadic-html (only for Scala.js)
- validation-xml test suite
- XML responses in http4s
- Apache daffodil test suite
- scala-xml-diff test suite
- xs4s test suite
- yaidom test suite
- xmlrpc for Scala test suite
- xtract test suite
- xml-lens (doesn't use literals?)
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.
- XML protocols (eg. SOAP, HTTP requests and responses, ...)
- HTML templating
- XML templating
- JSX syntax in React.js
- Setting Maven-style pom.xml settings