Python使用ElementTree解析XML

來源:互聯網
上載者:User

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

具體使用:
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.