# File raggle, line 1706
      def fix_character_encoding(element)
        # get character encoding
        enc = $config['character_encoding'] || 'ISO-8859-1'

        # check and see if we have iconv support
        if $HAVE_LIB['iconv'] && $config['use_iconv']
          unless $iconv
            # $iconv hasn't been intialized; create it
            enc += '//TRANSLIT' if $config['use_iconv_translit']
            $iconv = Iconv.new(enc, 'UTF-8')
          end

          # decode element using iconv
          element_text = element.text.to_s
          begin
            ret = $iconv.iconv(element_text) << $iconv.iconv(nil)
          rescue Iconv::IllegalSequence => e
            success_str = e.success
            ch, pending_str = e.failed.split(//, 2)
            ch_int = ch.to_i

            if String::UNICODE_LUT.has_key?(ch_int)
              $log.puts "[#{Time.now}] WARNING: converting unicode ##{ch_int}"
              element_text = success_str + UNICODE_LUT[ch_int] + pending_str
            else
              if $config['iconv_munge_illegal']
                $log.puts "[#{Time.now}] WARNING: munging unicode ##{ch_int}"
                munge_str = $config['unicode_munge_str']
                element_text = success_str + munge_str + pending_str
              else
                $log.puts "[#{Time.now}] WARNING: dropping unicode ##{ch_int}"
                element_text = success_str + pending_str
              end
            end
            retry
          end                                                                 
        else
          # iconv isn't installed, or it's disabled; fall back to
          # the old (oogly) encoding behavior
          ret = (REXML::Output.new('', enc) << element.text).to_s
        end

        # return result
        ret.unescape_html
      end