12

具体来说,替换字符串中特殊XML 字符的最简单和最惯用的方法是什么。例如,转换<Jack & Jill>&lt;Jack &amp; Jill&gt;.

4

3 回答 3

28

事实证明有一种简单的方法可以做到这一点(尽管快速的网络搜索没有发现明显的解决方案):只需使用 method xml.Utility.escape

于 2013-06-25T15:59:51.533 回答
2

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

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

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.

于 2017-04-27T06:40:17.673 回答
0

我建议使用该功能org.apache.commons.text.StringEscapeUtils.escapeHtml4,添加build.sbtlibraryDependencies += "org.apache.commons" % "commons-text" % "1.9"

xml.Utility.escape逃避例如« &laquo;

于 2021-03-24T18:59:06.253 回答