Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在通过 minidom 创建 XML 元素:
ele = doc.createElement("ele") main.appendChild(ele) ele.attributes['name']= "bla"
但元素看起来:
<ele name="bla"/>
我想要的是:
<ele name="bla"></ele>
这两种形式是等价的。如果您真的想要结束标记,请向元素添加一个空文本节点:
>>> ele = doc.createElement('ele') >>> ele.attributes['name']= "bla" >>> ele.appendChild(doc.createTextNode('')) >>> print ele.toxml() <ele name="bla"></ele>