require 'rexml/document' include REXML #- rexml sanity check (bugs in ruby 1.8.4, ruby 1.8.6) xmldoc = Document.new("") xmldoc << XMLDecl.new(XMLDecl::DEFAULT_VERSION, "UTF-8") content = ['61c3a927223c3e26'].pack("H*") #- is some UTF-8 text but just to make sure my editor won't magically convert.. xmldoc.root.add_attribute('attr', content) out = [] xmldoc.write(out, 0) xmldoc = REXML::Document.new(out.join) sanity1 = xmldoc.root.attributes['attr'] out = [] xmldoc.write(out, 0) xmldoc = REXML::Document.new(out.join) sanity2 = xmldoc.root.attributes['attr'] puts "REXML sanity outcome (correctly readable on a UTF-8 system only): sanity1=#{sanity1}, sanity2=#{sanity2}" if sanity1 != sanity2 puts "=> REXML sanity check *FAILED* (this is normal at least with unpatched ruby-1.8.4 or ruby-1.8.6, which ship a broken REXML)." exit 1 else puts "=> REXML sanity check OK" exit 0 end