gzip - How to read from zipped xml files in Scala code? -
how access xml data files directly zipped file in scala program? there direct ways programmatically unzip , read contents in scala code?
here couple of ways of doing in 2.8.1:
cat > root.xml << eof <root> <id>123</id> </root> eof zip root root.xml
and in repl:
val rootzip = new java.util.zip.zipfile("root.zip") import collection.javaconverters._ val entries = rootzip.entries.asscala entries foreach { e => val x = scala.xml.xml.load(rootzip.getinputstream(e)) println(x) }
or like:
val rootzip = new java.util.zip.zipfile("root.zip") import scala.collection.javaconversions._ rootzip.entries. filter (_.getname.endswith(".xml")). foreach { e => println(scala.xml.xml.load(rootzip.getinputstream(e))) }
Comments
Post a Comment