python处理xml的常用包(lib.xml、ElementTree、lxml)
python处理xml的三种常见机制
- dom(随机访问机制)
- sax(Simple APIs for XML,事件驱动机制)
- etree
python处理xml的三种包
- 标准库中的xml
- Fredrik Lundh 的 ElementTree
- Stefan Behnel 的 lxml
对以上三种包的介绍和对比
摘录自:http://infohost.nmt.edu/tcc/help/pubs/pylxml/web/index.html
With the continued growth of both Python and XML, there is a plethora(过剩/过多) of packages out there that help you read, generate, and modify XML files from Python scripts. Compared to most of them, the lxml package has two big advantages:
- Performance. Reading and writing even fairly large XML files takes an almost imperceptible(小得无法察觉的) amount of time.
- Ease of programming. The lxml package is based on ElementTree, which Fredrik Lundh invented to simplify and streamline XML processing.
lxml is similar in many ways to two other, earlier packages:
- Fredrik Lundh continues to maintain his original version of ElementTree.
- xml.etree.ElementTree is now an official part of the Python library. There is a C-language version called cElementTree which may be even faster than lxml for some applications.
However, the author prefers lxml for providing a number of additional features that make life easier. In particular, support for XPath makes it considerably easier to manage more complex XML structures.
标准库中的xml包
摘录自:http://docs.python.org/library/xml.html
The XML handling submodules are:
- xml.etree.ElementTree: the ElementTree API, a simple and lightweight XML processor
- xml.dom: the DOM API definition
- xml.dom.minidom: a minimal DOM implementation
- xml.dom.pulldom: support for building partial DOM trees
- xml.sax: SAX2 base classes and convenience functions
- xml.parsers.expat: the Expat parser binding
ElementTree包
PYPI的介绍:https://pypi.python.org/pypi/elementtree/
The Element type is a flexible container object, designed to store hierarchical data structures in memory. Element structures can be converted to and from XML.
其作者对lxml的推介:http://effbot.org/zone/element-index.htm
There’s also an independent implementation, lxml.etree, based on the well-known libxml2/libxslt libraries. This adds full support for XSLT, XPath, and more.
IBM文档库的介绍文章:XML 问题: 使用 ElementTree,以 Python 语言处理 XML
lxml介绍
摘录自:http://lxml.de/
lxml - XML and HTML with Python
lxml is the most feature-rich and easy-to-use library for processing XML and HTML in the Python language.
The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt. It is unique in that it combines the speed and XML feature completeness of these libraries with the simplicity of a native Python API, mostly compatible but superior to the well-known ElementTree API. The latest release works with all CPython versions from 2.6 to 3.6.
总结
一般情况下使用lxml可获得高效率和易用性。
扩展阅读
Python的XML处理方案:
Python XML解析
JAVA的xml方案:
java解析xml的几种方式
lxml教程:
Python XML processing with lxml
命名空间相关:
Parsing XML with lxml and elementtree
XML 命名空间
python处理xml的常用包(lib.xml、ElementTree、lxml)的更多相关文章
- python 常用包之xml文件处理
1,处理xml的包 from xml.etree import ElementTree as ET 2,如何写出xml文件 xml文件和html中的元素很像,有父级子集之说, root = ET.El ...
- Python常用内置模块之xml模块
xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言.从结构上,很像HTML超文本标记语言.但他们被设计的目的是不同的,超文本标记语言被设计用来显示 ...
- python常用模块之xml模块
python常用模块之xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单,不过,在json还没诞生的年代,大家都是使用xml,目前很多传统公司的系 ...
- Python之路(第十六篇)xml模块、datetime模块
一.xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单, xml比较早,早期许多软件都是用xml,至今很多传统公司如金融行业的很多系统的接口还主要 ...
- self._raiseerror(v) File "D:\GameDevelopment\Python27\lib\xml\etree\ElementTree.py", line 1506, in _raiseerror
D:\BaiDuYun\Plist>python unpack_plist.py lobbyRelieveTraceback (most recent call last): File &quo ...
- R语言︱文本挖掘套餐包之——XML+SnowballC+tm包
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- R语言︱文本挖掘套餐包之--XML+tm+Sn ...
- 常用模块(xml)
XML(可扩展性标记语言)是一种非常常用的文件类型,主要用于存储和传输数据.在编程中,对XML的操作也非常常见. 本文根据python库文档中的xml.etree.ElementTree类来进行介绍X ...
- C#中常用的读取xml的几种方法(转)
本文完全来源于http://blog.csdn.net/tiemufeng1122/article/details/6723764,仅作个人学习之用. XML文件是一种常用的文件格式,例如WinFor ...
- python项目练习3:万能的XML
1.目的 如何用XML来表示多种数据,以及如何使用适合XML或SAX的简单API来处理XML文本.目标是通过一个描述各种网页和目录的XML文件生成一个完整的网站. 注:有关XML的描述参见http:/ ...
随机推荐
- [Machine Learning] Probabilistic Graphical Models:一、Introduction and Overview(2、Factors)
一.什么是factors? 类似于function,将一个自变量空间投影到新空间.这个自变量空间叫做scope. 二.例子 如概率论中的联合分布,就是将不同变量值的组合映射到一个概率,概率和为1. 三 ...
- [转] CSS direction属性简介与实际应用 ---张鑫旭
一.用的少并不代表没有用 至少,在我接触的这么多项目里,没有见到使用过CSS direction属性做实际开发的. 为什么呢?是因为direction长得丑吗? 虽然说direction确实其貌不扬, ...
- ListView复用和优化详解
我们每一个Android开发人员对ListView的使用肯定是很熟悉的,然而多少人能真正的懂ListView的缓存机制呢,说白了就是ListView为了提高效率,而内部实现的一种优化,牺牲一点内存.而 ...
- Source kit service terminated Editor functionality temporarily limited
这下可好. Source kit service terminated Editor functionality temporarily limited 运行以下代码出现了以上的提示...另外,还压根 ...
- UltraEdit软件破解方法
一.说明 UltraEdit破解软件虽然带有“安装说明.txt”,但是我并没有弄懂--安装说明太模糊.经过一番摸索,找到了破解方法,现记录于此. 二.操作步骤 1.断开网络 2.安装软件 3.打开软件 ...
- ios8新特性widget开发-b
os8发布已经有一段时间了,伴随着ios8同时也出现了许多新的特性,ios系统将会越来越开放,这是好事.其中一个新特性就是在下拉通知栏里加入了个性的widget,开发者可以自己定义widget的样式内 ...
- Octopress 之 Mac 版环境配置
前提条件: 1.安装了 Git2.用 rbenv 或 RVM 安装了 Ruby 1.9.3 以上版本3.安装了 ExecJS 的一种支持 JavaScript 运行环境 一.安装 Octopress ...
- 防止 DDoS 攻击的五个「大招」!
提到 DDoS 攻击,很多人不会陌生.上周,美国当地时间 12 月 29 日,专用虚拟服务器提供商 Linode 遭到 DDoS 攻击,直接影响其 Web 服务器的访问,其中 API 调用和管理功能受 ...
- 【poj2891】同余方程组
同余方程组 例题1:pku2891Strange Way to Express Integers 中国剩余定理求的同余方程组mod 的数是两两互素的.然而本题(一般情况,也包括两两互素的情况,所以中国 ...
- 浅谈.Net和Java互相调用的三种方式
在很多的大型系统开发中,开发工具往往不限制于同一种开发语言,而是会使用多种开发语言的混合型开发.目前Java和.Net都声称自己占85%的市场份 额,不管谁对谁错,Java和.Net是目前应用开发的两 ...