如何避免在Scala中使用XML/HTML文档的字符串?

时间:2021-11-06 00:16:29

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;.

具体地说,替换字符串中特殊的XML字符最简单、最惯用的方法是什么?把《杰克与吉尔》改编成《杰克与吉尔》的最简单、最地道的方法是什么?Jill>。

2 个解决方案

#1


25  

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.

事实证明,有一种简单的方法可以做到这一点(尽管快速的web搜索并没有揭示明显的解决方案):只需使用方法xml.Utility.escape。

#2


1  

If you are looking to escape the @ sign in a scala.html file, for instance, using Scala/Play, do @@.

如果您希望在scala中转义@符号。例如,html文件,使用Scala/Play, do @。

And give the person who provided this answer here How to print @ symbol in HTML with play framework (scala) an upvote.

并给在这里提供答案的人如何使用play framework (scala)在HTML中打印@符号。

I came across this page while looking for the above answer, so I just wanted to duplicate it here since other people may end up here as well.

我在寻找上面的答案时偶然发现了这一页,所以我想在这里复制它,因为其他人也可能会在这里结束。

#1


25  

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.

事实证明,有一种简单的方法可以做到这一点(尽管快速的web搜索并没有揭示明显的解决方案):只需使用方法xml.Utility.escape。

#2


1  

If you are looking to escape the @ sign in a scala.html file, for instance, using Scala/Play, do @@.

如果您希望在scala中转义@符号。例如,html文件,使用Scala/Play, do @。

And give the person who provided this answer here How to print @ symbol in HTML with play framework (scala) an upvote.

并给在这里提供答案的人如何使用play framework (scala)在HTML中打印@符号。

I came across this page while looking for the above answer, so I just wanted to duplicate it here since other people may end up here as well.

我在寻找上面的答案时偶然发现了这一页,所以我想在这里复制它,因为其他人也可能会在这里结束。