Close a tag with no text in lxml

Posted by PulpFiction on Stack Overflow See other posts from Stack Overflow or by PulpFiction
Published on 2010-05-05T07:47:37Z Indexed on 2010/05/05 7:58 UTC
Read the original article Hit count: 256

Filed under:
|

I am trying to output a XML file using Python and lxml

However, I notice one thing that if a tag has no text, it does not close itself. An example of this would be:

root = etree.Element('document')
rootTree = etree.ElementTree(root)
firstChild = etree.SubElement(root, 'test')

The output of this is:

<document>
<test/>
</document

I want the output to be:

<document>
<test>
</test>
</document>

So basically I want to close a tag which has no text, but is used to the attribute value. How do I do that? And also, what is such a tag called? I would have Googled it, but I don't know how to search for it.

© Stack Overflow or respective owner

Related posts about python

Related posts about lxml