import lxml.etree as et
tree = et.parse('sample-ns.xml')
tree = tree.write('test.xml', encoding='utf-8', xml_declaration=True)
原始文件是:
<root xmlns='namespace'>
<element key='value'>text</element>
<element>text</element>tail
<empty-element/>
</root>
输出的文件是:
<?xml version='1.0' encoding='utf-8'?>
<root xmlns="namespace">
<element key="value">text</element>
<element>text</element>tail
<empty-element/>
</root>
没有评论:
发表评论