Skip to content

Instantly share code, notes, and snippets.

View martinjaimem's full-sized avatar

Martin Jaime martinjaimem

View GitHub Profile
@coffeejunk
coffeejunk / gist:3827905
Created October 3, 2012 16:10
ruby string for xml
In Ruby 1.9.2 to escape XML special characters in Strings, use the 'encode' method.
Example, if you have:
my_string = 'this is "my" complicated <String>'
For XML attributes use:
"<node attr=#{my_string.encode(:xml => :attr)} />"
Generates: