    # File lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 212
      def xml_out(ref, options = nil)
        handle_options('out', options)
        if ref.instance_of?(Array)
          ref = { @options['anonymoustag'] => ref }
        end

        if @options['keeproot']
          keys = ref.keys
          if keys.size == 1
            ref = ref[keys[0]]
            @options['rootname'] = keys[0]
          end
        elsif @options['rootname'] == ''
          if ref.instance_of?(Hash)
            refsave = ref
            ref = {}
            refsave.each { |key, value|
              if !scalar(value)
                ref[key] = value
              else
                ref[key] = [ value.to_s ]
              end
            }
          end
        end

        @ancestors = []
        xml = value_to_xml(ref, @options['rootname'], '')
        @ancestors = nil

        if @options['xmldeclaration']
          xml = @options['xmldeclaration'] + "\n" + xml
        end

        if @options.has_key?('outputfile')
          if @options['outputfile'].kind_of?(IO)
            return @options['outputfile'].write(xml)
          else
            File.open(@options['outputfile'], "w") { |file| file.write(xml) }
          end
        end
        xml
      end