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