require 'rexml/document'text = %{Some text\n Some more\n\n}REXML::Document.new(text, { :compress_whitespace => :all }).to_s# => "Some text\n Some more\n"