第一种长这样:
<标签>属性</标签>
<test>fisrt grandson</test>
第二种长这样:<标签 属性1 属性2/>
<test Name="reserved" age="31" Description="保留"/>
两种不同表现形式,就是通过ElementTree中write的最后一个参数决定的
short_empty_elements=FALSE时,开始/结束标记成对出现,就是第一种格式
short_empty_elements=True时,作为一个单独的自关闭状态标记,就是第二种格式
def write(self, file_or_filename,
encoding=None,
xml_declaration=None,
default_namespace=None,
method=None, *,
short_empty_elements=True):
"""Write element tree to a file as XML.
Arguments:
*file_or_filename* -- file name or a file object opened for writing
*encoding* -- the output encoding (default: US-ASCII)
*xml_declaration* -- bool indicating if an XML declaration should be
added to the output. If None, an XML declaration
is added if encoding IS NOT either of:
US-ASCII, UTF-8, or Unicode
*default_namespace* -- sets the default XML namespace (for "xmlns")
*method* -- either "xml" (default), "html, "text", or "c14n"
*short_empty_elements* -- controls the formatting of elements
that contain no content. If True (default)
they are emitted as a single self-closed
tag, otherwise they are emitted as a pair
of start/end tags