Module: ActiveSupport::XmlMini_REXML

Extended by:
XmlMini_REXML
Included in:
XmlMini_REXML
Defined in:
activesupport/lib/active_support/xml_mini/rexml.rb

Overview

:nodoc:

Constant Summary

CONTENT_KEY =
'__content__'.freeze

Instance Method Summary collapse

Instance Method Details

#parse(data) ⇒ Object

Parse an XML Document string or IO into a simple hash.

Same as XmlSimple::xml_in but doesn't shoot itself in the foot, and uses the defaults from Active Support.

data

XML Document string or IO to parse



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'activesupport/lib/active_support/xml_mini/rexml.rb', line 18

def parse(data)
  if !data.respond_to?(:read)
    data = StringIO.new(data || '')
  end

  char = data.getc
  if char.nil?
    {}
  else
    data.ungetc(char)
    silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
    doc = REXML::Document.new(data)

    if doc.root
      merge_element!({}, doc.root)
    else
      raise REXML::ParseException,
        "The document #{doc.to_s.inspect} does not have a valid root"
    end
  end
end