instance method xml_in

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.2.3

Signature

xml_in(string = nil, options = nil)

Converts an XML document in the same way as the Perl module XML::Simple.

string

XML source. Could be one of the following:

  • nil: Tries to load and parse ‘<scriptname>.xml’.

  • filename: Tries to load and parse filename.

  • IO object: Reads from object until EOF is detected and parses result.

  • XML string: Parses string.

options

Options to be used.

Parameters

string opt = nil
options opt = nil
Source
# File activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 149
  def xml_in(string = nil, options = nil)
    handle_options('in', options)

    # If no XML string or filename was supplied look for scriptname.xml.
    if string.nil?
      string = File::basename($0)
      string.sub!(/\.[^.]+$/, '')
      string += '.xml'

      directory = File::dirname($0)
      @options['searchpath'].unshift(directory) unless directory.nil?
    end

    if string.instance_of?(String)
      if string =~ /<.*?>/m
        @doc = parse(string)
      elsif string == '-'
        @doc = parse($stdin.readlines.to_s)
      else
        filename = find_xml_file(string, @options['searchpath'])

        if @options.has_key?('cache')
          @options['cache'].each { |scheme|
            case(scheme)
            when 'storable'
              content = @@cache.restore_storable(filename)
            when 'mem_share'
              content = @@cache.restore_mem_share(filename)
            when 'mem_copy'
              content = @@cache.restore_mem_copy(filename)
            else
              raise ArgumentError, "Unsupported caching scheme: <#{scheme}>."
            end
            return content if content
          }
        end
        
        @doc = load_xml_file(filename)
      end
    elsif string.kind_of?(IO) || string.kind_of?(StringIO)
      @doc = parse(string.readlines.to_s)
    else
      raise ArgumentError, "Could not parse object of type: <#{string.type}>."
    end

    result = collapse(@doc.root)
    result = @options['keeproot'] ? merge({}, @doc.root.name, result) : result
    put_into_cache(result, filename)
    result
  end

Defined in activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb line 149 · View on GitHub · Improve this page · Find usages on GitHub

Defined in XmlSimple

Type at least 2 characters to search.

↑↓ navigate · open · esc close