A common idiom in Java before Scala, go / list Java to Scala list

I am processing an XML document and iterating through the nodes. I want to iterate over the nodes and create a new list of some kind. How do I do it with Scala:

Here is my XML reverse code:

  def findClassRef(xmlNode: Elem) = {

    xmlNode\"classDef" foreach { (entry) =>
        val name    = entry \ "@name"
        val classid = entry \ "@classId"
        println(name + "//" + classid)
    }
  }

      

If there is a println line, I want to add items to the list.

+2


a source to share


1 answer


The card should work. If you don't need a specific List instance, you can delete the toList.



xmlNode \"classDef" map { (entry) =>
  val name    = entry \ "@name"
  val classid = entry \ "@classId"
  name + "//" + classid
} toList

      

+4


a source







All Articles