Can't import scala.xml._

Given the following line of code in a Scala worksheet:

import scala.xml._


this error is generated:

Error: object xml is not a member of package scala


A similar line of code works:
import 
scala.io.Source

Seems basic, but I've been searching for over an hour with no solution!  Have tried or found:

settings at:  Preferences->General->Auto Import
help page at https://www.jetbrains.com/idea/help/managing-imports-in-scala.html

Using IntelliJ IDEA 15.1, scala-sdk-2.11.7

Thanks in advance for any help!

3 comments
Comment actions Permalink

Found an answer.
https://github.com/scala/scala-xml says: "As of Scala 2.11, this library is a separate jar that can be omitted from Scala projects that do not use XML."
Thus scala-xml needs to be downloaded & included as a dependency:
cmd-; Project Settings -> Modules -> Dependencies
click + in bottom-left -> 2 Library -> From Maven
In the search box of the popup, type the library name "scala-xml" and click the search icon.  A long list of possibilities shows up, and I chose the most recent version corresponding to my version of Scala, 2.11.

1
Comment actions Permalink

Thanks, Mark.  This was a big help!

0
Comment actions Permalink

You can also use SBT for this.  See https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT to get started with SBT.  Once that is setup, all you need to do is update your build.sbt file with no need to update the project settings in Idea.  Fully functional build.sbt file shown below.

name := "AppName"

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies ++= Seq("org.scala-lang.modules" % "scala-xml_2.11" % "1.0.6")

1

Please sign in to leave a comment.