Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 10. Herding XML in Scala > Recap and What’s Next - Pg. 216

</author> <id></id> {for (post <- posts) yield <entry> <title>{post.title}</title> <link href={"" + post.slug + ".html"} rel="alternate"/> <id>{post.atomId}</id> <updated>{post.atomDate}</updated> <content type="html">{post.body}</content> <author> <name>John Doe</name> <uri></uri> </author> </entry> } </feed> } def write = XML.saveFull("/tmp/atom-example.xml", feed, "UTF-8", true, null) We're making heavy use of the ability to escape out to Scala expressions in this example. Whenever we need a piece of dynamic information--for example, the date of the first post in the sequence, formatted for the Atom standard--we simply escape out and write Scala as we normally would. In the latter half of the <feed> element, we use a for comprehension to yield successive blocks of dynamically formatted XML. The write method of AtomFeed demonstrates the use of the saveFull method, provided by the scala.xml library. saveFull writes an XML document to disk, optionally in dif-