import java.lang._
import com.ximpleware._
object Sample {
def main(args :Array[String])= {
// println("helloo")
try{
var i :Int = -1
val vgen :VTDGen= new VTDGen()
val ap :AutoPilot =new AutoPilot()
ap.selectXPath("CATALOG/CD/COUNTRY/text()")
if(vgen.parseFile("../catalog.xml", false)) {
val vnav :VTDNav = vgen.getNav()
ap.bind(vnav)
while((i=ap.evalXPath)!= -1) {
println(vnav.toString(i))
println(vnav.toNormalizedString(vnav.getText()))
}
ap.resetXPath()
}
}
catch {
case e :Exception => println(e)
}
}
}
I have imported VTD-XML Library It compiles Well but On Execution prints an Exception
:java.lang.ArrayIndexOutOfBoundsException: -1
I have solved the while issue in the code. But the problem is I always get -1 for ap.evalXPAth
As John McCrae said; the while check will not fly in scala. Instead you can define a new while construction like this for -1-ending calls:
This is a simplified example of an invocation that read from the keyboard until you give -1: