How to use xml.Utility.unescape?

After I read the xml.Utility.unescape SDK xml.Utility.unescape , I would think that this is the opposite of xml.Utility.escape , but it doesn't seem to do anything:

 scala> xml.Utility.escape("& <") res0: String = &amp; &lt; scala> val sb = new StringBuilder sb: StringBuilder = scala> xml.Utility.unescape("&amp; &lt;", sb) res1: StringBuilder = null scala> sb.toString res2: String = "" 

How to use xml.Utility.unescape ?

+4
source share
1 answer

I checked the unescape documentation and I am very disappointed ...

Adds an immutable string to s, amp becomes &, lt becomes <, etc.

returns null if ref was not a predefined entity.

So it seems that unescape designed to add a single character to a StringBuilder . He thought "&amp; &lt;" was "not a predefined entity", so it returned null for your res1 .

Some tests in REPL:

 scala> unescape("amp", sb) res9: StringBuilder = & scala> unescape("lt", sb) res10: StringBuilder = &< scala> unescape(" ", sb) res11: StringBuilder = null 
+4
source

Source: https://habr.com/ru/post/1469483/


All Articles