3. Code and XML
val name = “Scala course”
val xml = <xhtml>
<body>
<p>Hello, { name }</p>
</body>
</xhtml>
4. Code and XML 2
val names = List(“Alf”, “Fredrik”)
<ul>{ for (name <- names)
yield <li>{ name }</li>
}</ul>
5. XML (de)serialization
val xml = xml.XML.loadFile(“filename.xml”)
xml.XML.saveFull(“filename.xml”, xml,
“UTF-8”, true, null)
6. XML parsing
xml “ul” // xml.NodeSeq
xml “li”
xml “ul” “li”
xml “a” “@href” // xml.NodeSeq.Empty
<p>Hello</p>.text // java.lang.String (“Hello”)
7. XML pattern matching
xml match {
case <ul>{contents}</ul> => “Unordered list”
case <ol>{contents}</ol> => “Ordered list”
case _ => “Something else”
}