Reputation: 3678
I have a simple groovy script where I want to escape a String for XML...
@Grapes(@Grab(group='org.apache.commons', module='commons-lang3',version='3.9'))
import org.apache.commons.lang3.StringEscapeUtils
def value = "[Apple MacBook Pro with Touch Bar - 15.4 & Core i7 - 16 GB RAM - 512 GB SSD]"
StringEscapeUtils.escapeXml11(value.toString())
As per the docs, it looks like this method just needs a String, so why is it giving this exception...
No signature of method: static org.apache.commons.lang3.StringEscapeUtils.escapeXml11() is applicable for argument types: (String) values: [[Apple MacBook Pro with Touch Bar - 15.4 & Core i7 - 16 GB RAM - 512 GB SSD]]
Upvotes: 0
Views: 5227
Reputation: 160191
You have a non-printable character in your code:
Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000: 53 74 72 69 6E 67 45 73 63 61 70 65 55 74 69 6C StringEscapeUtil
00000010: 73 2E 65 73 63 61 70 65 58 6D 6C 31 31 E2 80 8B s.escapeXml11b..
00000020: 28 76 61 6C 75 65 2E 74 6F 53 74 72 69 6E 67 28 (value.toString(
00000030: 29 29 0A )).
See after the Xml11
?
It works fine with normal characters.
Upvotes: 1
Reputation: 2357
I have tested and received the same error message, but I changed the method to escapeXml11
and it works now:
import org.apache.commons.lang3.StringEscapeUtils
class Program {
static void main(String[] args) {
testStringUtils()
}
private static void testStringUtils() {
def value = "[Apple MacBook Pro with Touch Bar - 15.4 & Core i7 - 16 GB RAM - 512 GB SSD]"
def sample = StringEscapeUtils.escapeXml11(value)
println(sample)
}
}
I am using version 3.9:
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
This is the output:
> Task :Program.main()
[Apple MacBook Pro with Touch Bar - 15.4 & Core i7 - 16 GB RAM - 512 GB SSD]
BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed
17:24:42: Task execution finished 'Program.main()'.
Upvotes: 1