2.4 xml support

796 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
796
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

2.4 xml support

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

×