scala/ScalaBook/chapter-05/xml.scala

import scala.xml._


var poem2 = 
  Elem(null, "poem", Null, TopScope,
       Elem(null, "title", Null, TopScope, Text("Magic Everywhere")),
       Elem(null, "poet", new UnprefixedAttribute("realname","yes", Null), TopScope, Text("Yannis Papadopoulos")),
       Elem(null, "stanza", Null, TopScope,
            Elem(null, "verse", Null, TopScope, Text("There's magic everywhere")),
            Elem(null, "verse", Null, TopScope, Text("When I see your blue eyes")) 
       )
  )           

//println(poem2)
var n = 10

var z = if (n>9) { Some(Text("In the Dark")) } else { None }
var poem = new Array[Elem](10)
    poem(0) =
   <poem>
   <title subtitle={z}>Magic Everywhere</title>
   <poet> Yannis Papadopoulos </poet>
   <year>{ new Atom(1942) }</year>
   <stanza> 
   <verse> There's magic everywhere  </verse>
   <verse> When I see your blue eyes </verse>
   </stanza>
   </poem>

println(poem(0))
val pp = new PrettyPrinter(80, 5)

var poem_title = (poem(0) \ "title").text
var poem_author  = (poem(0) \ "poet").text
println(poem_title+" "+poem_author)
println("--------------------------------------------------")
var poems=XML.loadFile("poems.xml")
println("**************************************************")
 for ( val poem <- poems \ "poem" ) 
   if ( (poem \ "year").text.trim.toInt >1960 ) {
     var poet = (poem \ "poet").text
     var title = (poem \ "title").text
     println("\""+title+"\" by "+poet)
   }     
////////////////////////////////////////////////////////////