class Quickbooks::Service::BaseService

def parse_collection(response, model)

def parse_collection(response, model)
  if response
    collection = Quickbooks::Collection.new
    xml = @last_response_xml
    begin
      results = []
      query_response = xml.xpath("//xmlns:IntuitResponse/xmlns:QueryResponse")[0]
      if query_response
        start_pos_attr = query_response.attributes['startPosition']
        if start_pos_attr
          collection.start_position = start_pos_attr.value.to_i
        end
        max_results_attr = query_response.attributes['maxResults']
        if max_results_attr
          collection.max_results = max_results_attr.value.to_i
        end
        total_count_attr = query_response.attributes['totalCount']
        if total_count_attr
          collection.total_count = total_count_attr.value.to_i
        end
      end
      path_to_nodes = "//xmlns:IntuitResponse//xmlns:#{model::XML_NODE}"
      collection.count = xml.xpath(path_to_nodes).count
      if collection.count > 0
        xml.xpath(path_to_nodes).each do |xa|
          results << model.from_xml(xa)
        end
      end
      collection.entries = results
    rescue => ex
      raise Quickbooks::IntuitRequestException.new("Error parsing XML: #{ex.message}")
    end
    collection
  else
    nil
  end
end