如何用Python创建生成xml文档文件的方法
导读:如何用Python创建生成xml文档文件的方法?#设置根节点root = Element('bookstore' tree = ElementTree(root #设置1级子节点child0 = Element('book', {'cate...
如何用Python创建生成xml文档文件的方法?
#设置根节点
root = Element('bookstore')
tree = ElementTree(root)
#设置1级子节点
child0 = Element('book', { 'category' : "COOKING"} )
root.append(child0)
#设置2级子节点
child00 = Element('title', { 'language' : "English"} )
child00.text = 'Everyday Italian' #2级子节点文本
child0.append(child00)
tree.write('test.xml', 'utf8')
其他的依照上述代码编写即可
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 如何用Python创建生成xml文档文件的方法
本文地址: https://pptw.com/jishu/66000.html
