Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Scala XML support work?

Tags:

xml

scala

I'm sure it should be obvious, but I could find any references on my question. What underlying technology does Scala XML uses? Is it something DOM-like or SAX-like or StAX like? What performance penalties should I be aware of when processing large documents? Is StAX still more efficient?

Thanks in advance.

like image 495
BorisOkunskiy Avatar asked Mar 06 '10 07:03

BorisOkunskiy


2 Answers

Large documents (several hundred of MB) can be processed with scala.xml.pull.XMLEventReader. See nightly scaladoc (assuming you'll be using 2.8). This is using a pull parser model like StAX.

In general compared to Java, Scala is doing its own thing when dealing with XML. The XML is immutable. Also you can use XML literals directly in your Scala code which tends to make the code more readable.

In response to the comment, XML.load uses javax.xml.parsers.{ SAXParser, SAXParserFactory } as underlying technology. I also assume that the resulting xml is loaded in memory.

like image 93
huynhjl Avatar answered Sep 21 '22 02:09

huynhjl


Scala does its own thing. Most of the XML models out there are mutable, and do not translate well to immutability (because they keep track of parent, mostly).

Here's a paper about it.

like image 27
Daniel C. Sobral Avatar answered Sep 18 '22 02:09

Daniel C. Sobral