python对xml文件写入操作
2017-07-17 15:36
375 查看
#Python写xml比较简单,直接使用xml模块的minidom即可对xml文件进行写入操作 from xml.dom.minidom import Document doc = Document() people = doc.createElement("people") doc.appendChild(people) aperson = doc.createElement("person") people.appendChild(aperson) name = doc.createElement("name") aperson.appendChild(name) personname = doc.createTextNode("Annie") name.appendChild(personname) filename = "people.xml" f = open(filename, "w") f.write(doc.toprettyxml(indent=" ")) f.close()
#上面代码对应输出:
<?xml version="1.0" ?> <people> <person> <name>Annie</name> </person> </people>
相关文章推荐
- python对xml的处理和文件的写入操作1
- 在Python程序中进行文件读取和写入操作的教程
- Python文件操作,无缓冲写入,直接对硬盘进行操作
- python操作文件写入内容
- python使用lxml操作XML文件
- python操作xml文件详细介绍
- 利用python操作android的xml资源文件,让其按照中文自动生成对应中文首字母加起来的名字,并且根据中文在java类里面替代对应的中文
- python开发_xml.etree.ElementTree_XML文件操作_该模块在操作XML数据是存在安全隐患_慎用
- python操作xml文件详细介绍
- python开发_xml.etree.ElementTree_XML文件操作_该模块在操作XML数据是存在安全隐患_慎用
- Python之XML文件操作
- [ZT]Python使用xml.etree.ElementTree操作xml文件
- Dom4j-操作节点和属性及写入其他xml文件
- Dom4j解析xml文件-操作节点和属性及写入其他xml文件
- Python中文件的读取和写入操作
- python文件操作之文件写入
- python操作xml文件详细介绍
- python菜鸟笔记--python读取和写入CSV文件操作
- 【python小练】0017-将xls文件内容写入xml文件中
- Python 写入XML 文件