如何用Python创建生成xml文档文件的方法

更新时间:02-02 教程 由 孤己i 分享

#设置根节点

root=Element('bookstore')

tree=ElementTree(root)

#设置1级子节点

child0=Element('book',{'category':"COOKING"})

root.append(child0)

#设置2级子节点

child00=Element('title',{'language':"English"})

child00.text='EverydayItalian'#2级子节点文本

child0.append(child00)

tree.write('test.xml','utf8')

其他的依照上述代码编写即可

声明:关于《如何用Python创建生成xml文档文件的方法》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2105289.html