Search code examples
htmlxmlscalaescaping

How to escape a string for use in XML/HTML document in Scala?


Specifically, what's the easiest and most idiomatic way to replace special XML characters in a string. E.g., what's the easiest and most idiomatic way to convert <Jack & Jill> to &lt;Jack &amp; Jill&gt;.


Solution

  • Turns out there is an easy way to do this (despite a quick web-search not revealing an obvious solution): just use method xml.Utility.escape.