Module: ActiveSupport::XmlMini_REXML

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

Overview

:nodoc:

Constant Summary collapse

CONTENT_KEY =
"__content__"

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



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

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

  if data.eof?
    {}
  else
    require_rexml unless defined?(REXML::Document)
    doc = REXML::Document.new(data)

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