我寫了一個簡單的scala程序來打開一個XML文件。如何使用Scala驗證XML文件的模式?
有沒有辦法讓scala根據它引用的模式文件來驗證XML文件?目前我的XML文件不符合模式,所以我期望在驗證時會出錯。
的XML文件引用這樣的模式中的根元素:
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="items.xsd">
的Scala代碼:
import scala.xml._
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world! " + args.toList)
val start = System.currentTimeMillis
val data = XML.loadFile(args(0))
val stop = System.currentTimeMillis
Console.println("Took " + (stop-start)/1000.0 + "s to load " + args(0))
}
}
HelloWorld.main(args)
此實現具有巨大的內存泄漏 – 2015-11-11 16:55:54