#設(shè)置根節(jié)點(diǎn)
root=Element('bookstore')
tree=ElementTree(root)
#設(shè)置1級(jí)子節(jié)點(diǎn)
child0=Element('book',{'category':"COOKING"})
root.append(child0)
#設(shè)置2級(jí)子節(jié)點(diǎn)
child00=Element('title',{'language':"English"})
child00.text='EverydayItalian'#2級(jí)子節(jié)點(diǎn)文本
child0.append(child00)
tree.write('test.xml','utf8')
其他的依照上述代碼編寫即可