Module: XmlMini_Nokogiri

Extended by:
XmlMini_Nokogiri
Included in:
XmlMini_Nokogiri
Defined in:
lib/xml_mini/nokogiri.rb

Defined Under Namespace

Modules: Conversions

Instance Method Summary collapse

Instance Method Details

#parse(data) ⇒ Object

Parse an XML Document string or IO into a simple hash using libxml / nokogiri.

data

XML Document string or IO to parse



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/xml_mini/nokogiri.rb', line 10

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

  char = data.getc
  if char.nil?
    {}
  else
    data.ungetc(char)
    doc = Nokogiri::XML(data)
    raise doc.errors.first if doc.errors.length > 0
    doc.to_hash
  end
end