在我阅读了xml.Utility.unescape的SDK文档后,我认为它是xml.Utility.escape的反向操作,但它似乎根本没有做任何事情: scala xml.Utility.escape(" ")res0: String = amp; lt;scala val sb = new StringBuildersb: StringBui
scala> xml.Utility.escape("& <") res0: String = & < scala> val sb = new StringBuilder sb: StringBuilder = scala> xml.Utility.unescape("& <", sb) res1: StringBuilder = null scala> sb.toString res2: String = ""
如何正确使用xml.Utility.unescape?
我查看了unescape文档,我非常失望……Appends unescaped string to s, amp becomes &, lt becomes < etc..
returns null if ref was not a predefined entity.
因此,看起来unescape意味着将单个字符附加到StringBuilder.它认为“& amp;& lt;”是“不是预定义的实体”所以它为你的res1返回null.
REPL中的一些测试:
scala> unescape("amp", sb) res9: StringBuilder = & scala> unescape("lt", sb) res10: StringBuilder = &< scala> unescape(" ", sb) res11: StringBuilder = null