Question

Originally I was trying to use Java APIs for this, but now I am going to see if I can use Scala to parse XML documents coming through an XML stream. The following is a basic setup of XMLEventReader:

val reader = new xml.pull.XMLEventReader(IOSource)
while (reader.hasNext) System.out.println(reader.next)

The problem is IOSource must be a form of scala.io.Source and I'm only seeing local file methods for such parsing. What native Scala APIs can I use to feed XML coming from streaming HTTP to the event reader?

Thanks!

Edit

Looks like a Java API is going to be necessary. So instead, is it possible to convert a Java InputStream into a Scala io.Source?

Was it helpful?

Solution

Scala 2.10.2 standard library scala.io.Source (you want object Source, not abstract class Source) offers a number of from* methods, including fromInputStream and fromURL.

Scala 2.9.X is, if I recall, similar if not the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top