Module: OEmbed::Formatter::XML::Backends::REXML

Extended by:
REXML
Included in:
REXML
Defined in:
lib/oembed/formatter/xml/backends/rexml.rb

Overview

Use the REXML library, part of the standard library, to parse XML values.

Instance Method Summary collapse

Instance Method Details

#decode(xml) ⇒ Object

Parses an XML string or IO and convert it into an object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oembed/formatter/xml/backends/rexml.rb', line 13

def decode(xml)
  if !xml.respond_to?(:read)
    xml = StringIO.new(xml)
  end
  obj = {}
  doc = ::REXML::Document.new(xml)
  doc.elements[1].elements.each do |el|
    obj[el.name] = el.text
  end
  obj
rescue
  case $!
  when parse_error
    raise $!
  else
    raise parse_error, "Couldn't parse the given document."
  end  
end

#decode_fail_msgObject



32
33
34
# File 'lib/oembed/formatter/xml/backends/rexml.rb', line 32

def decode_fail_msg
  "The version of the REXML library you have installed isn't parsing XML like ruby-oembed expected."
end

#parse_errorObject



36
37
38
# File 'lib/oembed/formatter/xml/backends/rexml.rb', line 36

def parse_error
  ::REXML::ParseException
end