- import elementtree.ElementTree as etree
- #从字符串中获取
- root = etree.fromstring(xmlstr)
- #从xml文件流读入
- #遍历root下的子节点
- for child in root:
- #若child标签的值不为空
- if child.text:
- #child标签名称
- child.tag
- #若标签下面还有层标签
- if child.getchildren():
2.5版本以前的没有包括这个模块。
不过可以搜:elementtree搜索到安装包。
下载elementtree-1.2.6-20050316.tar.gz
tar -zxvf ele......
cd ele。。。
python setup.py install
安装的时候需要root权限,因为要添加一些库文件到usr/lib目录下。
源:http://blog.csdn.net/codingkid/article/details/6596519