python读取xml文件参数

虫师-https://www.cnblogs.com/fnng/p/3581433.html

xml.dom篇

    DOM是Document Object Model的简称,XML 文档的高级树型表示。该模型并非只针对 Python,而是一种普通XML 模型。Python 的 DOM 包是基于 SAX 构建的,并且包括在 Python 2.0 的标准 XML 支持里。

一、xml.dom的简单介绍

1、主要方法:

minidom.parse(filename):加载读取XML文件
doc.documentElement:获取XML文档对象
node.getAttribute(AttributeName):获取XML节点属性值
node.getElementsByTagName(TagName):获取XML节点对象集合
node.childNodes :返回子节点列表。
node.childNodes[index].nodeValue:获取XML节点值
node.firstChild:访问第一个节点,等价于pagexml.childNodes[0]
返回Node节点的xml表示的文本:
doc = minidom.parse(filename)
doc.toxml('UTF-8')

访问元素属性:

Node.attributes["id"]
a.name #就是上面的 "id"
a.value #属性的值 

转自https://www.jb51.net/article/50863.htm

原文地址:https://www.cnblogs.com/ohlala/p/13444592.html