Python etree control empty tag format

前端 未结 5 1598
小蘑菇
小蘑菇 2020-12-06 10:32

When creating an XML file with Python\'s etree, if we write to the file an empty tag using SubElement, I get:


5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 11:23

    This was directly solved in Python 3.4. From then, the write method of xml.etree.ElementTree.ElementTree has the short_empty_elements parameter which:

    controls the formatting of elements that contain no content. If True (the default), they are emitted as a single self-closed tag, otherwise they are emitted as a pair of start/end tags.

    More details in the xml.etree documentation.

提交回复
热议问题