Module: Quickbooks::Support

Defined in:
lib/quickbooks/ruby_ext.rb

Defined Under Namespace

Modules: Amount, Date, DateTime, Float, Integer, TimeInterval

Class Method Summary collapse

Class Method Details

.parse_xml(xml) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/quickbooks/ruby_ext.rb', line 135

def self.parse_xml(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(event[2].empty? ? QB[event[1]].instantiate : QB[event[1]].instantiate(event[2]))
    when :end_element
      if stack.size > 1
        temp = stack.pop
        stack.last.attributes << temp
      end
    when :text, :cdata
      stack.last.value = event[1].unescape_xml if stack.last.class < Quickbooks::Property
    end
  end
  obj = stack.pop
  obj.send(:clean!)
  obj
end