Skip to content

Instantly share code, notes, and snippets.

@amclain
Created February 17, 2015 23:22
Show Gist options
  • Save amclain/af8889a5eaac3ad68160 to your computer and use it in GitHub Desktop.
Save amclain/af8889a5eaac3ad68160 to your computer and use it in GitHub Desktop.
REXML Line Feed Bug
Write Text: "bar"
Read Text: "\n bar\n "
XML String:
<root>
<foo>
bar
</foo>
</root>
require 'rexml/document'
xml_string = ''
REXML::Document.new(xml_string).tap do |doc|
doc.add_element('root').tap do |root|
write_text = 'bar'
puts "Write Text: #{write_text.inspect}"
root.add_element('foo').text = write_text
end
doc.write output: xml_string, indent: 4
end
REXML::Document.new(xml_string).tap do |doc|
read_text = doc.elements['/root/foo'].first
puts "Read Text: #{read_text.inspect}"
end
puts "XML String:"
puts xml_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment