Module: ActiveSupport::XmlMini_JDOM

Extended by:
XmlMini_JDOM
Included in:
XmlMini_JDOM
Defined in:
lib/active_support/xml_mini/jdom.rb

Overview

:nodoc:

Constant Summary collapse

CONTENT_KEY =
'__content__'.freeze
NODE_TYPE_NAMES =
%w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
PROCESSING_INSTRUCTION_NODE TEXT_NODE}

Instance Method Summary collapse

Instance Method Details

#parse(data) ⇒ Object

Parse an XML Document string or IO into a simple hash using Java’s jdom.

data

XML Document string or IO to parse



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_support/xml_mini/jdom.rb', line 32

def parse(data)
  if data.respond_to?(:read)
    data = data.read
  end

  if data.blank?
    {}
  else
    @dbf = DocumentBuilderFactory.new_instance
    xml_string_reader = StringReader.new(data)
    xml_input_source = InputSource.new(xml_string_reader)
    doc = @dbf.new_document_builder.parse(xml_input_source)
    merge_element!({}, doc.document_element)
  end
end