title: REXML and encoding
body: <p>Can anyone please explain this result for me?</p>
  
  <pre><code>#!/usr/bin/env ruby
  # encoding: utf-8
  
  require 'rexml/document'
  
  doc = REXML::Document.new(DATA)
  puts "doc: #{doc.encoding}"
  REXML::XPath.each(doc, '//item') do |item|
    puts "  #{item}: #{item.to_s.encoding}"
  end
  
  __END__
  &lt;doc&gt;
    &lt;item&gt;Test&lt;/item&gt;
    &lt;item&gt;Über&lt;/item&gt;
    &lt;item&gt;8&lt;/item&gt;
  &lt;/doc&gt;
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>doc: UTF-8
    &lt;item&gt;Test&lt;/item&gt;: US-ASCII
    &lt;item&gt;Über&lt;/item&gt;: UTF-8
    &lt;item&gt;8&lt;/item&gt;: US-ASCII
  </code></pre>
  
  <p>It seems as if REXML doesn't care what the document encoding is, and starts autodetecting encoding for each item... Am I doomed to <code>encode('UTF-8')</code> each string I pull out of REXML, even though UTF-8 is the original encoding? What is happening here?</p>