'Write a dict as elements, possibly recursively.'

def write_iterable_as_elements(self, values):

    if isinstance(values, dict):
        values = values.iteritems()
    for (name, value) in values:
        if isinstance(value, basestring):
            self.output_stream.write(('%s    <%s>%s</%s>\n' % (self.indent, name, saxutils.escape(value), name)))
        else:
            self.output_stream.write(('%s    <%s>\n' % (self.indent, name)))
            self.depth += 1
            self.indent = ('    ' * self.depth)
            self.write_iterable_as_elements(value)
            self.depth -= 1
            self.indent = ('    ' * self.depth)
            self.output_stream.write(('%s    </%s>\n' % (self.indent, name)))
