Scala - Getting the error scala.xml.NodeSeq



I am trying to write code to import XML file. I am missing some basic things -- Here is the code.



import xml._

case class Menu(name: List[String])
case class BreakFastMenu(food: List[Menu], price: List[Menu], des: List[Menu], cal: List[Menu])

def toMenu(node : Node): Menu = {
val menuChart = (node \ "food")
Menu(menuChart)
}

def toBreakFastMenu(node: Node): BreakFastMenu = {
val name = (node \ "name").map(toMenu).toList
val price = (node \ "price").map(toMenu).toList
val des = (node \ "description").map(toMenu).toList
val cal = (node \ "calories").map(toMenu).toList
BreakFastMenu(name, price, des, cal)
}

val menuXML = XML.loadFile("simple.xml")
val food = (menuXML \ "food").map(toBreakFastMenu).toArray
food.foreach(println)


And the XML file is here - simple.xml Getting the error as



MenuXML.scala:9: error: type mismatch;
found : scala.xml.NodeSeq
required: List[String]
Menu(menuChart)
^
one error found


Can anyone sort me out what the basics I am missing .


No comments:

Post a Comment