如何用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')
其他的依照上述代码编写即可
还没有评论,来说两句吧...