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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…