Reputation: 3974
Now (2014) that the support for XML literals in Scala is officially deprecated, what is the recommended way to work with XML in Scala? My current requirements are XSD support, XML transformations.
One way to do these is to convert the XML input to native Scala collections, use the collections API to make the transformations, then convert back to XML (a different format). Simple, but is this really the best solution? How about XSD support?
If I had to use Java I would probably use Saxon, which I had used in the past with good experiences. Is there anything even remotely comparable for Scala?
EDIT: Trying to close this. This question should probably have been asked on programmers.stackexchange.com as it is not about a specific problem, so it is too vague for this site.
Upvotes: 2
Views: 129
Reputation: 12104
They deprecated XML literals because users were annoyed by the celebrity status it got, that is: Why should XML have higher status than alternatives like JSON?
To mend this, the Scala team added string interpolation, which allows you to do things like these:
val name = "Niko"
val age = 21
println(s"hi, I'm $name, and I'm $age years old") // prints: hi, I'm Niko, and I'm 21 years old
Note the little "s" at the beginning of the string. The scala team didn't just include the interpolated string; they also added a means for you to make your own!
So doing that you'd be able to do something like this:
val xmlObj = xml"<body>$data</body>"
or
val jsonObj = json"""{"body": "$data"}"""
And then have it convert to de-serialized xml or json objects that you can work with
You can read more about how this works in practice here: http://docs.scala-lang.org/overviews/core/string-interpolation.html
Upvotes: 1