# File lib/deltacloud.rb, line 181
    def xml_to_class(base_object, item)

      return nil unless item

      params = {
          :id => item['id'],
          :url => item['href'],
          :name => item.name,
          :client => self
      }
      params.merge!({ :initial_state => (item/'state').text.sanitize }) if (item/'state').length > 0

      obj = base_object.new(params)
      # Traverse across XML document and deal with elements
      item.xpath('./*').each do |attribute|
        # Do a link for elements which are links to other REST models
        if self.entry_points.keys.include?("#{attribute.name}s""#{attribute.name}s")
          obj.add_link!(attribute.name, attribute['id']) && next unless (attribute.name == 'bucket' && item.name == 'blob')
        end

        # Do a HWP property for hardware profile properties
        if attribute.name == 'property'
          if attribute['value'] =~ /^(\d+)\.(\d+)$/
            obj.add_hwp_property!(attribute['name'], attribute, :float) && next
          else
            obj.add_hwp_property!(attribute['name'], attribute, :integer) && next
          end
        end

        # If there are actions, add they to ActionObject/StateFullObject
        if attribute.name == 'actions'
          (attribute/'link').each do |link|
            (obj.add_run_action!(item['id'], link) && next) if link[:rel] == 'run'
            obj.add_action_link!(item['id'], link)
          end && next
        end

        if attribute.name == 'mount'
          obj.add_link!("instance", (attribute/"./instance/@id").first.value)
          obj.add_text!("device", (attribute/"./device/@name").first.value)
          next
        end

        #deal with blob metadata
        if (attribute.name == 'user_metadata')
          meta = {}
          attribute.children.select {|x| x.name=="entry" }.each  do |element|
            value = element.content.gsub!(/(\n) +/,'')
            meta[element['key']] = value
          end
          obj.add_collection!(attribute.name, meta.inspect) && next
        end

        if (['public_addresses', 'private_addresses'].include? attribute.name)
          obj.add_addresses!(attribute.name, (attribute/'*')) && next
        end

        if ('authentication'.include? attribute.name)
          obj.add_authentication!(attribute[:type], (attribute/'*')) && next
        end

        #deal with providers
        if(attribute.name == 'provider')
          obj.add_provider!(attribute.attributes['id'].value, (attribute/'entrypoint')) && next
        end

        # Deal with collections like public-addresses, private-addresses
        if (attribute/'./*').length > 0
          obj.add_collection!(attribute.name, (attribute/'*').collect { |value| value.text }) && next
        end

        #deal with blobs for buckets
        if(attribute.name == 'blob')
          obj.add_blob!(attribute.attributes['id'].value) && next
        end

        # Anything else is treaten as text object
        obj.add_text!(attribute.name, attribute.text.convert)
      end
      return obj
    end