require 'rexml/document'
text = %{<doc><a>Some whitespace</a> <b>Some more</b></doc>} REXML::Document.new(text, { :compress_whitespace => :all, :ignore_whitespace_nodes => :all }).to_s # => "<doc><a>Some text</a><b>Some more</b></doc>"