【发布时间】:2018-03-09 10:32:21
【问题描述】:
import scala.io.Source
import scala.xml.{Node, NodeSeq, XML}
object scalaTest extends App {
var test= <name>person
<fname>doe
<first>john</first>
</fname>
</name>
var s=scala.io.StdIn.readLine
var result=s.asInstanceOf[NodeSeq]
println(result)
}
当我在命令行上提供 xpath test\"fname"\"first" 时,它会抛出,
test\"fname"\"first"
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to scala.xml.NodeSeq
at scalaTest$.delayedEndpoint$scalaTest$1(scalaTest.scala:15)
at scalaTest$delayedInit$body.apply(scalaTest.scala:4)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at scalaTest$.main(scalaTest.scala:4)
at scalaTest.main(scalaTest.scala)
如何在命令行中提供 xpath 作为 test\"fname"\"first" 并得到结果,
<first>john</first>
【问题讨论】:
-
我没有在 Scala 中使用 XML 的经验,但不应该与在您的代码中进行测试相关吗?或者这些有什么关系?
标签: xml scala xpath command-line