'How to load (open and read) an XML file in Scala'에 해당되는 글 1건

  1. 2014.03.28 How to load (open and read) an XML file in Scala
00.scala2014. 3. 28. 15:37
반응형

Scala FAQ: How do I load an XML file in Scala? (How do I open and read an XML file in Scala?)

I demonstrated this in my earlier Scala XML - Searching XMLNS namespaces, XPath tutorial, but you can load an XML file in Scala like this:

import scala.xml.XML
val xml = XML.loadFile("/Users/al/Projects/Scala/yahoo-weather.xml")

Once you've loaded the file contents like that, you can manipulate them as desired, such as searching the XML using XPath constructs like this:

val temp = (xml \\ "channel" \\ "item" \ "condition" \ "@temp") text

In summary, if you need to load an XML file in Scala, I hope this has been helpful.

Posted by 1010