java - NodeSq 不符合预期的整数类型

标签 java xml scala

我无法将 scala xml 值解析为整数。如何解决?

错误:

NodeSq does not conform to expected type integer

代码:

import scala.io._
import scala.xml._

object Weather {
  def main(args: Array[String]) {
    getWeatherData()
  }
  def getWeatherData()={
    val url = "http://api.openweathermap.org/data/2.5/weather?q=Berlin&mode=xml"
    val responce = scala.io.Source.fromURL(url).mkString
    val xmlResponce = XML.loadString(responce)
    val kelvin: Integer = xmlResponce \\ "temperature" \\ "@value"
    println( kelvin-273.15)
  }

}

最佳答案

(xmlResponce\\"温度"\\"@value").text.toInt

关于java - NodeSq 不符合预期的整数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26335351/

相关文章:

.net - MSTest 的 XML 单元测试框架

java - 如何在 Google map 上触发 map 事件 < v3

xml - 如何读取 XML 输入文件、操作某些节点(删除并重命名某些节点)并将输出写入新的 XML 输出文件?

java - Selenium chromedriver 意外停止

java - 获取像 "Two classes have the same XML type name..."这样的 JAXB 异常

scala - 可以在 Scala 中创建大小类型吗?

scala - 如何在 Spark Udf 中传递 map ?

regex - Scala 正则表达式无法运行

java - Openfire Smack 连接问题

Java 嵌入式数据库比较