For a XML snippet like this:
val fruits =
<fruits>
<fruit>
<name>apple</name>
<taste>ok</taste>
</fruit>
<fruit>
<name>banana</name>
<taste>better</taste>
</fruit>
</fruits>
doing something like:
fruits \\ "fruit"
will return a sequence of type scala.xml.NodeSeq
with all the fruits and sub nodes inside.
What is the best way to convert this to a list of JSON objects? I'm trying to send my list of fruits back to a browser. I had a look at scala.util.parsing.json.JSONObject
and scala.util.parsing.json.JSONArray
, but I don't know how to get from NodeSeq to anyone of the latter.
If at all possible, I would love to see how it's done with plain Scala code.