spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Scala - Getting the error scala.xml.NodeSeq


You are mixing up the types. Menu takes List[String] and not scala.xml.NodeSeq.

You get the error, because you are passing the whole node (scala.xml.NodeSeq), not just the content of it.

I can recommend this blogpost to review for further explanation: http://alvinalexander.com/scala/how-to-extract-data-from-xml-nodes-in-scala

I would recommend to get your representation right first always. The best way to organize your case classes is to match the structure of the nodes. E.g. in case of a <food> node, you'd probably want to introduce a Food class.

  import xml._

  case class Food(food: String, price: String,
des: String, cal: String)
  case class BreakFastMenu(foodItems: List[Food])

  def toFood(node : Node): Food = {        
    val name = (node  "name").text
    val price = (node  "price").text
    val des = (node  "description").text
    val cal = (node  "calories").text
    Food(name, price, des, cal)
  }


  val menuXML =
XML.load("http://www.w3schools.com/xml/simple.xml")
  val breakFastMenu = BreakFastMenu((menuXML 
"food").map(toFood).toList)
  breakFastMenu.foodItems.foreach(println)

Categories : Xml

Related to : Scala - Getting the error scala.xml.NodeSeq
Remove prefixed attribute in scala (scala-xml)
You can't remove a prefixed attribute with remove(String) because of its implementation: From Attribute.scala: def remove(key: String) = if (!isPrefixed && this.key == key) next else copy(next remove key) As you can see, if the attribute is prefixed, the first branch condition is false. However, there is a different function in the same class: def remove(namespace: String, scop

Categories : Xml
Is Scala Either really a Monad
Yes, it really is - otherwise it would be in scalaz-outlaws. Either's bind is defined something like: trait Either[A, B] { def bind[C](f: B => Either[A, C]) = this match { case Right(b) => f(b) case Left(a) => Left(a) } } (in practice it's defined via a typeclass, but the above definition would work) I guess it's more proper to say that for a fixed A, the type ({type L[B]=

Categories : Scala
Why does SBT want to get org.scala-sbt while it has already been installed?
Why does sbt need to download the package of itself again? Because you can easily change SBT version, it has to be able to download JAR files for different SBT versions. So what you actually install is just a shell script which knows how to retrieve SBT launcher if it isn't already, and how to launch it if it is.

Categories : Java
Scala build process
IntelliJ has build in support for sbt projects. My work flow is the following : Create a project (in the shell) using sbt. Basically you have to create a build.sbt and the necessary directory structure `src/main/scala` `src/main/resources` `src/test/` The in IntelliJ just do Open -> select build.sbt. Also check auto-import checkbox. Everything should work after this. NOTE: You may have

Categories : Scala
Can I tell scala.xml to match any of two tags?
If you take a look at the source for \ in NodeSeq.scala you can see that it's really just a bit of sugar for a filter operation over descendant_or_self, which is a List[Node], using the node's label. So you could do the same thing yourself, matching against a set of labels, like this: val searchedLabels = Set("p", "div") val results = body.descendant_or_self.filter(node => searchedLabels.con

Categories : Scala
Recently Add
get array result with wsdl and complexType
Same xml element in different places
How to post XML data to plone view and return xml data to sender?
Should a REST service expose a XSD for XML responses?
Querying a log file with multiple XML objects
How to set sorter of a List in Controller in SAPUI5?
XSLT Creating repetitive elements from Complex XML with Field and Metadata ids
and in a xml element
XML Nodes to be inserted with XSLT into a second Stylesheet
wso2 esb smooks un/edifact 96a EDI to XML
A complex type without an element in XSD
Convert rows of spreadsheet to separate XML files
XSLT mapping with metadata and field tags with multiple repetitive elements
Scala - Getting the error scala.xml.NodeSeq
XSLT - get value of all nodes with the same name
XSLT string join error
How do I parse XML web service in Swift?
Creating a complexType from multiple complexTypes
XSL repeating the same value but counting the correct number of different values
trying to export a complex xml from excel 2013
vb.net XML For loop
Chrome 39 XML/XSLT Renders Blank Page
How to make a drop down menu using xslt and xml?
xslt tokenize() and "Not a node item" error
Perl dies on big XML file, using STDIN
How to use custom sorter in XML views
distinct-values, contains function failed
Xslt code for fetching name value basing on the id value given in input
DonĀ“t preload images in XML (google maps API v3)
rename and send all child nodes based on value of element in child node in xslt
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.