用python内置的xml.dom可以对xml文件进行解析处理。
什么是xml?
XML 指可扩展标记语言(EXtensible Markup Language)
XML 是一种标记语言,很类似 HTML
XML 的设计宗旨是传输数据,而非显示数据
XML 被设计为具有自我描述性。
XML 是 W3C 的推荐标准
xml.dom具体操作实例:
本例通过xml模块对xml文件进行写入操作
from xml.dom.minidom import Document <a href="https://www.gaodaima.com/tag/doc" title="查看更多关于doc的文章" target="_blank">doc</a> = 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()
www#gaodaima.com来源gao@!dai!ma.com搞$$代^@码网搞代码
来源:搞代码网:原文地址:https://www.gaodaima.com