I have the following xml-node:
val xml = <fields><field name="one"></field><field name="two"></field></fields>
Now I would like to create a Map[String, Node] with the field-name as key.
for{x <- xml \ "field"} yield Map(x \ "@name" -> x)
Using yield above I get a List of Maps though:
List(Map((one,<field name="one"></field>)), Map((two,<field name="two"></field>)))
How do I functionally get a Map[String, Node] without going the imperative way (temp-vars) to transform the Maps in the List to the final desired Map, maybe without yield?
xml \ "field" map { x => ((x \ "@name").text -> x) } toMap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With