生成 XML
68.2 生成 XML
Element 构建树,tostring 输出。
创建节点
import xml.etree.ElementTree as ET
root = ET.Element('students')
child = ET.SubElement(root, 'student', name='小明')
child.text = '95'
print(ET.tostring(root, encoding='unicode'))
Element 构建树,tostring 输出。
import xml.etree.ElementTree as ET
root = ET.Element('students')
child = ET.SubElement(root, 'student', name='小明')
child.text = '95'
print(ET.tostring(root, encoding='unicode'))