Skip to content

Instantly share code, notes, and snippets.

@june29
Created June 1, 2009 05:06
Show Gist options
  • Save june29/121244 to your computer and use it in GitHub Desktop.
Save june29/121244 to your computer and use it in GitHub Desktop.
class String
def to_xml
self.unpack('U*').collect { |c|
if c >= 255
'&#' + c.to_s + ';'
elsif c == 165 || c == 92
'\\'
else
c.chr
end
}.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment