Reputation:
After I read xml.Utility.unescape
's SDK document, I would think that it is the reverse action of xml.Utility.escape
, however it does not seem to do anything at all:
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 = ""
How to correctly use xml.Utility.unescape
?
Upvotes: 4
Views: 2080
Reputation: 13922
I checked out the unescape
documentation and I'm pretty disappointed...
Appends unescaped string to s, amp becomes &, lt becomes < etc..
returns null if ref was not a predefined entity.
So it seems like unescape
is meant to append a single character to the StringBuilder
. It thought that "& <"
was "not a predefined entity" so it returned null
for your res1
.
Some testing in the REPL:
scala> unescape("amp", sb)
res9: StringBuilder = &
scala> unescape("lt", sb)
res10: StringBuilder = &<
scala> unescape(" ", sb)
res11: StringBuilder = null
Upvotes: 5