'Generate a <batch> XML tree to send to cloudsearch for
adding/updating/deleting the given things'

def xml_from_things(self):

    batch = etree.Element('batch')
    self.batch_lookups()
    version = self._version()
    for thing in self.things:
        try:
            if (thing._spam or thing._deleted):
                delete_node = self.delete_xml(thing, version)
                batch.append(delete_node)
            elif self.should_index(thing):
                add_node = self.add_xml(thing, version)
                batch.append(add_node)
        except (AttributeError, KeyError) as e:
            if (not self.use_safe_get):
                raise
            else:
                g.log.warning('Ignoring    problem    on    thing    %r.\n\n%r', thing, e)
    return batch
