Check that self.content != None before creating text nodes

This fixes cases like foo.content = None becoming <foo>None</foo> instead of <foo/>.