Module: HTTParty::Parsers::XML
- Defined in:
- lib/httparty/parsers/xml.rb
Overview
:nodoc:
Class Method Summary collapse
Class Method Details
.parse(xml) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/httparty/parsers/xml.rb', line 183 def self.parse(xml) stack = [] parser = REXML::Parsers::BaseParser.new(xml) while true event = parser.pull case event[0] when :end_document break when :end_doctype, :start_doctype # do nothing when :start_element stack.push REXMLUtilityNode.new(event[1], event[2]) when :end_element if stack.size > 1 temp = stack.pop stack.last.add_node(temp) end when :text, :cdata stack.last.add_node(event[1]) unless event[1].strip.length == 0 || stack.empty? end end stack.pop.to_hash end |