Leave whitespace for anchor
require 'rexml/document' text = %{<doc><a>Some whitespace</a> <b>Some more</b></doc>} REXML::Document.new(text, { :respect_whitespace => %w{a} }).to_s # => "<doc><a>Some whitespace</a> <b>Some more</b></doc>"