python生成xml怎么添加<xml version="1.0" encoding="UTF-8
发布网友
发布时间:2022-04-19 02:54
我来回答
共1个回答
热心网友
时间:2022-04-19 04:23
tree.write('createxml.xml',xml_declaration=True, encoding='utf-8', method="xml")
root = ET.Element('bookstore')
tree = ET.ElementTree()
tree._setroot(root)
child0 = ET.Element('book',{'category':"COOKING"})
root.append(child0)
child00 = ET.Element('title',{'language':"English"})
child00.text='Everyday Italian'
child0.append(child00)
tree.write('createxml.xml','utf-8')