How to parse an XML file in Scala using VTD-XML library?
Does Anyone know How to parse large XML files using Xpa开发者_C百科th using vtd-xml library in Scala?
This works on my local machine:
import com.ximpleware.{VTDGen, VTDNav, AutoPilot}
val vtdgen = new VTDGen()
val autopilot = new AutoPilot()
autopilot.selectXPath("/CATALOG/CD/COUNTRY/text()")
if (vtdgen.parseFile("catalog.xml", false)) {
val vtdnav = vtdgen.getNav()
autopilot.bind(vtdnav)
var i = -1
while({i = autopilot.evalXPath; i} != -1) {
println(vtdnav.toString(i))
println(vtdnav.toNormalizedString(vtdnav.getText()))
}
}
autopilot.resetXPath()
Outputs on input of catalog.xml:
USA
USA
UK
UK
UK
UK
USA
USA
@ huynhjl :Thank You.. It Works Well.
Use
println(vtdnav.toString(i-1))
println(vtdnav.toNormalizedString(vtdnav.getText()))
to get the output as
COUNTRY
USA
COUNTRY
UK
COUNTRY
UK
COUNTRY
USA
精彩评论