# File lib/amazon/search.rb, line 527
      def parse
        products = []

        doc = REXML::Document.new self
        begin
          total_results = doc.elements['ProductInfo/TotalResults'].text.to_i
        rescue # don't be strict about this for now
        end

        doc.elements.each('ProductInfo/Details') do |detail|
          product = Product.new(detail.attributes['url'])

          detail.elements.each do |property|

            if property.has_elements?

              case property.name
              # deal with elements that have more than one sub-level
                
              when 'BrowseList'
                browsenames = property.elements.map do |e|
                                e.elements.map { |e| e.text }
                              end.flatten
                product.instance_variable_set(:@browselist, browsenames)

              when 'Reviews'
                # can be either AverageCustomerRating or AverageRating
                avg = property.elements[1].text
                tcr = property.elements[2].text

                list =
                  property.elements.map { |e| e.elements.map { |e| e.text } }
                reviews = []
                list.each do |r|
                  reviews << Product::Review.new(*r) unless r.empty?
                end
                product.instance_variable_set(:@avgcustomerrating, avg)

                if tcr.to_i > 0         # not all review sets have this attribute
                  product.instance_variable_set(:@totalcustomerreviews, tcr)
                end

                product.instance_variable_set(:@reviews, reviews)

              else  # deal with the rest
                members = property.elements.map { |e| e.text }

                # better than Object#instance_eval, but still
                product.instance_variable_set(
                  "@#{property.name.downcase}".to_sym, members)
              end

            else       # these elements have no children

              # more ugliness
              product.instance_variable_set(
                "@#{property.name.downcase}".to_sym, property.text)
            end

          end
          products << product

        end

        products

      end