Michael
Michael

Reputation: 42110

XML unescaping with Zipper in Scala

Suppose I need to unescape XML escaped characters in a given string: e.g. I need to replace &amp; with &, &quot; with ", &lt; with < etc. I would prefer a purely functional solution.

Does it make sense to do it with scalaz.Zipper ? Zipper allows checking the characters to the right of the focus and skipping them while moving forward. Won't it be an overkill ? Would you suggest a simpler solution ?

Upvotes: 0

Views: 118

Answers (1)

lmm
lmm

Reputation: 17431

Zipper is better at dealing with 1:1 character-character mapping that needs access to the characters on either side, not a mapping that changes the number of characters in the string.

I'd recommend either using an XML parsing library (scala has a reasonable built-in-ish one in the form of scala-xml), a string escaping/unescaping utility function (there's one in apache commons that handles xml entities IIRC) or if you really want a fancy solution then maybe parsing your string with scala-parser-combinators.

Upvotes: 1

Related Questions