ElementTree / Python - 如何在节点中插入单个标签?

ElementTree / Python - How to insert single tag in a node?

大家

这有效,但结果是:

new = ET.Element("tagname")
new.text = "data"
i.insert(0,new)

结果:

<tagname></tagname>

我要

<tagname/>

可能吗?谢谢

它被称为子元素: https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.SubElement