Scala Cookbook: Bonus Chapters

Authors

Editor E-Repository FTI UWGM

Synopsis

Scala has built-in support for XML, so you can freely mix XML literals into your Scala
source code. This is nice, because instead of using strings to represent XML, you create
XML literals that the compiler can understand and verify. This approach lets you easily
generate dynamic XML by interweaving Scala code and XML in the same expressions.
On the flip side, when it comes to searching XML for the data you need, you can use
XPath methods like \ and \\ to find what you’re looking for, and other methods like
child, label, and attributes to iterate over elements and extract information.
As a word of caution, if you want to parse poorly formed XHTML, don’t try to do this
with the XML library. See my blog post for examples of how to use the Java
HTMLCleaner library to solve this problem.

Published

July 16, 2025

Series