Python使用ElementTree解析XML

ElementTree(元素树)。

ElementTree是XML解析库,已经在Python2.5之后被包括在标准库中

ElementTree感觉就像一个轻量级的DOM,具有方便使用、十分友好的API。除了代码可复用之外,它运行速度快,消耗内存较少。这里我们重点推荐使用ElementTree。如果需要使用XML解析器,不妨先试一试ElementTree。

2.5 之前的版本需要安装elementtree包,可以在 http://effbot.org/downloads/#elementtree 下载 相应版本的包,然后使用root命令执行已下命令安装:

tar zxvf elementtree-1.2.6-20050316.tar.gz

cd elementtree-1.2.6-20050316

chmod +x *.py

./setup.py install


[root@gd37vm01 elementtree-1.2.6-20050316]# ./setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/elementtree
copying elementtree/ElementInclude.py -> build/lib/elementtree
copying elementtree/SgmlopXMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/ElementTree.py -> build/lib/elementtree
copying elementtree/ElementPath.py -> build/lib/elementtree
copying elementtree/XMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/__init__.py -> build/lib/elementtree
copying elementtree/SimpleXMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/TidyHTMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/TidyTools.py -> build/lib/elementtree
copying elementtree/SimpleXMLWriter.py -> build/lib/elementtree
copying elementtree/HTMLTreeBuilder.py -> build/lib/elementtree
running install_lib
copying build/lib/elementtree/ElementInclude.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/SgmlopXMLTreeBuilder.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/ElementTree.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/ElementPath.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/XMLTreeBuilder.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/__init__.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/SimpleXMLTreeBuilder.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/TidyHTMLTreeBuilder.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/TidyTools.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/SimpleXMLWriter.py -> /usr/lib/python2.4/site-packages/elementtree
copying build/lib/elementtree/HTMLTreeBuilder.py -> /usr/lib/python2.4/site-packages/elementtree


具体使用:

你可能感兴趣的:(xml,python,api,Build)