This method is a context manager for writing and closing an element.

def element(self, name, attrs=None):
    """This method is a context manager for writing and closing an element."""
    self.open(name, attrs)
    yield
    self.close()