Great!
From the link Peter provided.
His example that encodes ASCII text for XML using the Filter action with Encode HTML Entities is here:
FWIW I use this instead in a lot of my scripts that work with KM xml:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
set unencodedText to "test¥&<me>\"'"
set encodedText to (current application's NSXMLNode's textWithStringValue:unencodedText)'s XMLString() as text
return encodedText
-->test¥&<me>"'
It doesn't encode single and double quotes but I've not had a problem with that.
This version would do that:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
set encodedText to (((current application's NSXMLNode's textWithStringValue:unencodedText)'s XMLString()'s stringByReplacingOccurrencesOfString:"'" withString:"'")'s stringByReplacingOccurrencesOfString:"\"" withString:""") as text
-->test¥&<me>"'
return encodedText
--> test¥&<me>"'