Skip to content
Snippets Groups Projects
Commit 980e7ecf authored by Christian Maeder's avatar Christian Maeder
Browse files

parsing all files

parent 46adf004
No related branches found
No related tags found
No related merge requests found
package scala
import java.io.File
import scala.xml._
/**
* Created by maeder on 13.01.15.
* try parsing <error> tags
*/
object ParseXML {
def readXml(f: File): NodeSeq = {
try {
val xml = XML.loadFile(f.getPath)
xml \\ "error"
} catch {
case e: SAXParseException => Nil
}
}
def getAttrs(attrs: List[String], x: Node): List[String] = {
attrs map (a => (x \ ("@" + a)).toString())
}
def traverse(dir: File, proc: File => Unit): Unit =
dir.listFiles foreach { f => if (f.isDirectory) traverse(f, proc) else proc(f)}
def procFile(f: File): Unit = {
val errs = readXml(f)
if (errs.isEmpty) println("NOERR: " + f)
else errs map (x => {
println(f)
getAttrs(List("type", "shortMsg", "level"), x) map println
}
)
}
def main(args: Array[String]): Unit = {
val dir = new File("/local/maeder/tptp/Distribution/errors")
traverse(dir, procFile)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment