ElementTree(元素树)(二)

  1. import elementtree.ElementTree as etree  
  2.   
  3. #从字符串中获取  
  4. root = etree.fromstring(xmlstr)  
  5. #从xml文件流读入  
  6.   
  7. #遍历root下的子节点  
  8. for child in root:  
  9.   
  10. #若child标签的值不为空  
  11. if child.text:  
  12.   
  13. #child标签名称  
  14. child.tag  
  15.   
  16. #若标签下面还有层标签  
  17. 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

 

猜你喜欢

转载自km-moon11.iteye.com/blog/2234744