Created
February 17, 2015 23:22
-
-
Save amclain/af8889a5eaac3ad68160 to your computer and use it in GitHub Desktop.
REXML Line Feed Bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write Text: "bar" | |
Read Text: "\n bar\n " | |
XML String: | |
<root> | |
<foo> | |
bar | |
</foo> | |
</root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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