require 'delegate'
require 'rexml/text'
require 'rexml/document'
class EntitySubstituter < DelegateClass(IO)
def initialize(io, document, filter=nil)
@document = document
@filter = filter
super(io)
end
def <<(s)
super(REXML::Text::unnormalize(s, @document.doctype, @filter))
end
end
str = %{
]>
&product; v&version;
}
doc = REXML::Document.new str
output = EntitySubstituter.new($stdout, doc)
doc.write(output)