NodeSq不符合预期的类型整数

时间:2014-10-13 08:01:54

标签: 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)
  }

}

1 个答案:

答案 0 :(得分:1)

(xmlResponce \\ "temperature" \\ "@value").text.toInt