handle_options (XmlSimple)

    # File lib/xmlsimple.rb, line 317
      def handle_options(direction, options)
        @options = options || Hash.new

        raise ArgumentError, "Options must be a Hash!" unless @options.instance_of?(Hash)

        unless KNOWN_OPTIONS.has_key?(direction)
          raise ArgumentError, "Unknown direction: <#{direction}>."
        end

        known_options = KNOWN_OPTIONS[direction]
        @options = normalize_option_names(@options, known_options)

        unless @default_options.nil?
          known_options.each { |option|
            unless @options.has_key?(option)
              if @default_options.has_key?(option)
                @options[option] = @default_options[option]
              end
            end
          }
        end

        unless @options.has_key?('noattr')
            @options['noattr'] = false
        end

        if @options.has_key?('rootname')
          @options['rootname'] = '' if @options['rootname'].nil?
        else
          @options['rootname'] = DEF_ROOT_NAME
        end

        if @options.has_key?('xmldeclaration') && @options['xmldeclaration'] == true
          @options['xmldeclaration'] = DEF_XML_DECLARATION
        end

        if @options.has_key?('contentkey')
          if @options['contentkey'] =~ /^-(.*)$/
            @options['contentkey']    = $1
            @options['collapseagain'] = true
          end
        else
          @options['contentkey'] = DEF_CONTENT_KEY
        end

        unless @options.has_key?('normalisespace')
          @options['normalisespace'] = @options['normalizespace']
        end
        @options['normalisespace'] = 0 if @options['normalisespace'].nil?

        if @options.has_key?('searchpath')
          unless @options['searchpath'].instance_of?(Array)
            @options['searchpath'] = [ @options['searchpath'] ]
          end
        else
          @options['searchpath'] = []
        end

        if @options.has_key?('cache') && scalar(@options['cache'])
          @options['cache'] = [ @options['cache'] ]
        end

        @options['anonymoustag'] = DEF_ANONYMOUS_TAG unless @options.has_key?('anonymoustag')

        if !@options.has_key?('indent') || @options['indent'].nil?
          @options['indent'] = DEF_INDENTATION
        end

        @options['indent'] = '' if @options.has_key?('noindent')

        # Special cleanup for 'keyattr' which could be an array or
        # a hash or left to default to array.
        if @options.has_key?('keyattr')
          if !scalar(@options['keyattr'])
            # Convert keyattr => { elem => '+attr' }
            #      to keyattr => { elem => ['attr', '+'] }
            if @options['keyattr'].instance_of?(Hash)
              @options['keyattr'].each { |key, value|
                if value =~ /^([-+])?(.*)$/
                  @options['keyattr'][key] = [$2, $1 ? $1 : '']
                end
              }
            elsif !@options['keyattr'].instance_of?(Array)
              raise ArgumentError, "'keyattr' must be String, Hash, or Array!"
            end
          else
            @options['keyattr'] = [ @options['keyattr'] ]
          end
        else
          @options['keyattr'] = DEF_KEY_ATTRIBUTES
        end

        if @options.has_key?('forcearray')
          if @options['forcearray'].instance_of?(Regexp)
            @options['forcearray'] = [ @options['forcearray'] ]
          end

          if @options['forcearray'].instance_of?(Array)
            force_list = @options['forcearray']
            unless force_list.empty?
              @options['forcearray'] = {}
              force_list.each { |tag|
                if tag.instance_of?(Regexp)
                  unless @options['forcearray']['_regex'].instance_of?(Array)
                    @options['forcearray']['_regex'] = []
                  end
                  @options['forcearray']['_regex'] << tag
                else
                  @options['forcearray'][tag] = true
                end
              }
            else
              @options['forcearray'] = false
            end
          else
            @options['forcearray'] = @options['forcearray'] ? true : false
          end
        else
          @options['forcearray'] = DEF_FORCE_ARRAY
        end

        if @options.has_key?('grouptags') && !@options['grouptags'].instance_of?(Hash)
          raise ArgumentError, "Illegal value for 'GroupTags' option - expected a Hash."
        end

        if @options.has_key?('variables') && !@options['variables'].instance_of?(Hash)
          raise ArgumentError, "Illegal value for 'Variables' option - expected a Hash."
        end

        if @options.has_key?('variables')
          @_var_values = @options['variables']
        elsif @options.has_key?('varattr')
          @_var_values = {}
        end
      end