main.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. lxml
  2. ====
  3. .. meta::
  4. :description: lxml - the most feature-rich and easy-to-use library for working with XML and HTML in the Python language
  5. :keywords: Python, XML, HTML, lxml, simple, ElementTree, etree, objectify, parsing, validation, XPath, XSLT
  6. .. class:: pagequote
  7. | `» lxml takes all the pain out of XML. « <http://thread.gmane.org/gmane.comp.python.lxml.devel/3252/focus=3258>`_
  8. | Stephan Richter
  9. .. class:: eyecatcher
  10. lxml is the most feature-rich
  11. and easy-to-use library
  12. for working with XML and HTML
  13. in the Python language.
  14. ..
  15. 1 Introduction
  16. 2 Documentation
  17. 3 Download
  18. 4 Mailing list
  19. 5 Bug tracker
  20. 6 License
  21. 7 Old Versions
  22. Introduction
  23. ------------
  24. lxml is a Pythonic binding for the libxml2_ and libxslt_ libraries. It is
  25. unique in that it combines the speed and feature completeness of these
  26. libraries with the simplicity of a native Python API, mostly compatible but
  27. superior to the well-known ElementTree_ API. See the introduction_ for more
  28. information about background and goals. Some common questions are answered in
  29. the FAQ_.
  30. .. _libxml2: http://xmlsoft.org
  31. .. _libxslt: http://xmlsoft.org/XSLT
  32. .. _introduction: intro.html
  33. .. _FAQ: FAQ.html
  34. Documentation
  35. -------------
  36. The complete lxml documentation is available for download as `PDF
  37. documentation`_. The HTML documentation from this web site is part of
  38. the normal `source download <#download>`_.
  39. * ElementTree:
  40. * `ElementTree API`_
  41. * compatibility_ and differences of lxml.etree
  42. * `benchmark results`_
  43. * lxml.etree:
  44. * the `lxml.etree Tutorial`_
  45. * `lxml.etree specific API`_ documentation
  46. * the `generated API documentation`_ as a reference
  47. * parsing_ and validating_ XML
  48. * `XPath and XSLT`_ support
  49. * Python `extension functions`_ for XPath and XSLT
  50. * `custom element classes`_ for custom XML APIs (see `EuroPython 2008 talk`_)
  51. * a `SAX compliant API`_ for interfacing with other XML tools
  52. * a `C-level API`_ for interfacing with external C/Pyrex modules
  53. * lxml.objectify:
  54. * `lxml.objectify`_ API documentation
  55. * a brief comparison of `objectify and etree`_
  56. lxml.etree follows the ElementTree_ API as much as possible, building it on
  57. top of the native libxml2 tree. If you are new to ElementTree, start with the
  58. `lxml.etree Tutorial`_. See also the ElementTree compatibility_ overview and
  59. the `benchmark results`_ comparing lxml to the original ElementTree_ and
  60. cElementTree_ implementations.
  61. Right after the `lxml.etree Tutorial`_ and the ElementTree_ documentation, the
  62. most important place to look is the `lxml.etree specific API`_ documentation.
  63. It describes how lxml extends the ElementTree API to expose libxml2 and
  64. libxslt specific functionality, such as XPath_, `Relax NG`_, `XML Schema`_,
  65. `XSLT`_, and `c14n`_. Python code can be called from XPath expressions and
  66. XSLT stylesheets through the use of `extension functions`_. lxml also offers
  67. a `SAX compliant API`_, that works with the SAX support in the standard
  68. library.
  69. There is a separate module `lxml.objectify`_ that implements a data-binding
  70. API on top of lxml.etree. See the `objectify and etree`_ FAQ entry for a
  71. comparison.
  72. In addition to the ElementTree API, lxml also features a sophisticated API for
  73. `custom element classes`_. This is a simple way to write arbitrary XML driven
  74. APIs on top of lxml. As of version 1.1, lxml.etree has a new `C-level API`_
  75. that can be used to efficiently extend lxml.etree in external C modules,
  76. including custom element class support.
  77. .. _ElementTree: http://effbot.org/zone/element-index.htm
  78. .. _`ElementTree API`: http://effbot.org/zone/element-index.htm#documentation
  79. .. _cElementTree: http://effbot.org/zone/celementtree.htm
  80. .. _`lxml.etree Tutorial`: tutorial.html
  81. .. _`generated API documentation`: api/index.html
  82. .. _`benchmark results`: performance.html
  83. .. _`compatibility`: compatibility.html
  84. .. _`lxml.etree specific API`: api.html
  85. .. _`parsing`: parsing.html
  86. .. _`validating`: validation.html
  87. .. _`XPath and XSLT`: xpathxslt.html
  88. .. _`extension functions`: extensions.html
  89. .. _`custom element classes`: element_classes.html
  90. .. _`SAX compliant API`: sax.html
  91. .. _`C-level API`: capi.html
  92. .. _`lxml.objectify`: objectify.html
  93. .. _`objectify and etree`: FAQ.html#what-is-the-difference-between-lxml-etree-and-lxml-objectify
  94. .. _`EuroPython 2008 talk`: s5/lxml-ep2008.html
  95. .. _XPath: http://www.w3.org/TR/xpath
  96. .. _`Relax NG`: http://www.relaxng.org/
  97. .. _`XML Schema`: http://www.w3.org/XML/Schema
  98. .. _`XSLT`: http://www.w3.org/TR/xslt
  99. .. _`c14n`: http://www.w3.org/TR/xml-c14n
  100. Download
  101. --------
  102. The best way to download lxml is to visit `lxml at the Python Package
  103. Index`_ (PyPI). It has the source that compiles on various platforms.
  104. The source distribution is signed with `this key`_. Binary builds for
  105. MS Windows usually become available through PyPI a few days after a
  106. source release. If you can't wait, consider trying a less recent
  107. release version first.
  108. The latest version is `lxml 2.2.2`_, released 2009-06-21
  109. (`changes for 2.2.2`_). `Older versions`_ are listed below.
  110. Please take a look at the `installation instructions`_!
  111. This complete web site (including the generated API documentation) is
  112. part of the source distribution, so if you want to download the
  113. documentation for offline use, take the source archive and copy the
  114. ``doc/html`` directory out of the source tree.
  115. It's also possible to check out the latest development version of lxml
  116. from svn directly, using a command like this::
  117. svn co http://codespeak.net/svn/lxml/trunk lxml
  118. You can also browse the `Subversion repository`_ through the web, or
  119. take a look at the `Subversion history`_. Please read `how to build lxml
  120. from source`_ first. The `latest CHANGES`_ of the developer version
  121. are also accessible. You can check there if a bug you found has been
  122. fixed or a feature you want has been implemented in the latest trunk
  123. version.
  124. .. _`lxml at the Python Package Index`: http://pypi.python.org/pypi/lxml/
  125. .. _`this key`: pubkey.asc
  126. .. _`Older versions`: #old-versions
  127. .. _`installation instructions`: installation.html
  128. .. _`how to build lxml from source`: build.html
  129. .. _`Subversion repository`: http://codespeak.net/svn/lxml/
  130. .. _`Subversion history`: https://codespeak.net/viewvc/lxml/
  131. .. _`latest CHANGES`: http://codespeak.net/svn/lxml/trunk/CHANGES.txt
  132. Mailing list
  133. ------------
  134. Questions? Suggestions? Code to contribute? We have a `mailing list`_.
  135. You can search the archive with Gmane_ or Google_.
  136. .. _`mailing list`: http://codespeak.net/mailman/listinfo/lxml-dev
  137. .. _Gmane: http://blog.gmane.org/gmane.comp.python.lxml.devel
  138. .. _Google: http://www.google.com/webhp?q=site:codespeak.net%2Fmailman%2Flistinfo%2Flxml-dev+
  139. Bug tracker
  140. -----------
  141. lxml uses the `launchpad bug tracker`_. If you are sure you found a bug in
  142. lxml, please file a bug report there. If you are not sure whether some
  143. unexpected behaviour of lxml is a bug or not, please ask on the `mailing
  144. list`_ first. Do not forget to search the archive (e.g. with Gmane_)!
  145. .. _`launchpad bug tracker`: https://launchpad.net/lxml/
  146. License
  147. -------
  148. The lxml library is shipped under a `BSD license`_. libxml2 and libxslt2
  149. itself are shipped under the `MIT license`_. There should therefore be no
  150. obstacle to using lxml in your codebase.
  151. .. _`BSD license`: http://codespeak.net/svn/lxml/trunk/doc/licenses/BSD.txt
  152. .. _`MIT license`: http://www.opensource.org/licenses/mit-license.html
  153. Old Versions
  154. ------------
  155. See the web sites of lxml `1.3 <http://codespeak.net/lxml/1.3/>`_,
  156. `2.0 <http://codespeak.net/lxml/2.0/>`_, `2.1
  157. <http://codespeak.net/lxml/2.1/>`_ and the `current in-development
  158. version <http://codespeak.net/lxml/dev/>`_.
  159. .. _`PDF documentation`: lxmldoc-2.2.2.pdf
  160. * `lxml 2.2.1`_, released 2009-06-02 (`changes for 2.2.1`_)
  161. * `lxml 2.2`_, released 2009-03-21 (`changes for 2.2`_)
  162. * `lxml 2.2beta4`_, released 2009-02-27 (`changes for 2.2beta4`_)
  163. * `lxml 2.2beta3`_, released 2009-02-17 (`changes for 2.2beta3`_)
  164. * `lxml 2.2beta2`_, released 2009-01-25 (`changes for 2.2beta2`_)
  165. * `lxml 2.2beta1`_, released 2008-12-12 (`changes for 2.2beta1`_)
  166. * `lxml 2.2alpha1`_, released 2008-11-23 (`changes for 2.2alpha1`_)
  167. * `lxml 2.1.5`_, released 2009-01-06 (`changes for 2.1.5`_)
  168. * `lxml 2.1.4`_, released 2008-12-12 (`changes for 2.1.4`_)
  169. * `lxml 2.1.3`_, released 2008-11-17 (`changes for 2.1.3`_)
  170. * `lxml 2.1.2`_, released 2008-09-05 (`changes for 2.1.2`_)
  171. * `lxml 2.1.1`_, released 2008-07-24 (`changes for 2.1.1`_)
  172. * `lxml 2.1`_, released 2008-07-09 (`changes for 2.1`_)
  173. * `lxml 2.0.11`_, released 2008-12-12 (`changes for 2.0.11`_)
  174. * `lxml 2.0.10`_, released 2008-11-17 (`changes for 2.0.10`_)
  175. * `lxml 2.0.9`_, released 2008-09-05 (`changes for 2.0.9`_)
  176. * `lxml 2.0.8`_, released 2008-07-24 (`changes for 2.0.8`_)
  177. * `lxml 2.0.7`_, released 2008-06-20 (`changes for 2.0.7`_)
  178. * `lxml 2.0.6`_, released 2008-05-31 (`changes for 2.0.6`_)
  179. * `lxml 2.0.5`_, released 2008-05-01 (`changes for 2.0.5`_)
  180. * `lxml 2.0.4`_, released 2008-04-14 (`changes for 2.0.4`_)
  181. * `lxml 2.0.3`_, released 2008-03-26 (`changes for 2.0.3`_)
  182. * `lxml 2.0.2`_, released 2008-02-22 (`changes for 2.0.2`_)
  183. * `lxml 2.0.1`_, released 2008-02-13 (`changes for 2.0.1`_)
  184. * `lxml 2.0`_, released 2008-02-01 (`changes for 2.0`_)
  185. * `lxml 1.3.6`_, released 2007-10-29 (`changes for 1.3.6`_)
  186. * `lxml 1.3.5`_, released 2007-10-22 (`changes for 1.3.5`_)
  187. * `lxml 1.3.4`_, released 2007-08-30 (`changes for 1.3.4`_)
  188. * `lxml 1.3.3`_, released 2007-07-26 (`changes for 1.3.3`_)
  189. * `lxml 1.3.2`_, released 2007-07-03 (`changes for 1.3.2`_)
  190. * lxml 1.3.1, released 2007-07-02 (`changes for 1.3.1`_)
  191. * `lxml 1.3`_, released 2007-06-24 (`changes for 1.3`_)
  192. * `lxml 1.2.1`_, released 2007-02-27 (`changes for 1.2.1`_)
  193. * `lxml 1.2`_, released 2007-02-20 (`changes for 1.2`_)
  194. * `lxml 1.1.2`_, released 2006-10-30 (`changes for 1.1.2`_)
  195. * `lxml 1.1.1`_, released 2006-09-21 (`changes for 1.1.1`_)
  196. * `lxml 1.1`_, released 2006-09-13 (`changes for 1.1`_)
  197. * `lxml 1.0.4`_, released 2006-09-09 (`changes for 1.0.4`_)
  198. * `lxml 1.0.3`_, released 2006-08-08 (`changes for 1.0.3`_)
  199. * `lxml 1.0.2`_, released 2006-06-27 (`changes for 1.0.2`_)
  200. * `lxml 1.0.1`_, released 2006-06-09 (`changes for 1.0.1`_)
  201. * `lxml 1.0`_, released 2006-06-01 (`changes for 1.0`_)
  202. * `lxml 0.9.2`_, released 2006-05-10 (`changes for 0.9.2`_)
  203. * `lxml 0.9.1`_, released 2006-03-30 (`changes for 0.9.1`_)
  204. * `lxml 0.9`_, released 2006-03-20 (`changes for 0.9`_)
  205. * `lxml 0.8`_, released 2005-11-03 (`changes for 0.8`_)
  206. * `lxml 0.7`_, released 2005-06-15 (`changes for 0.7`_)
  207. * `lxml 0.6`_, released 2005-05-14 (`changes for 0.6`_)
  208. * `lxml 0.5.1`_, released 2005-04-09 (`changes for 0.5.1`_)
  209. * `lxml 0.5`_, released 2005-04-08
  210. .. _`lxml 2.2.2`: lxml-2.2.2.tgz
  211. .. _`lxml 2.2.1`: lxml-2.2.1.tgz
  212. .. _`lxml 2.2`: lxml-2.2.tgz
  213. .. _`lxml 2.2beta4`: lxml-2.2beta4.tgz
  214. .. _`lxml 2.2beta3`: lxml-2.2beta3.tgz
  215. .. _`lxml 2.2beta2`: lxml-2.2beta2.tgz
  216. .. _`lxml 2.2beta1`: lxml-2.2beta1.tgz
  217. .. _`lxml 2.2alpha1`: lxml-2.2alpha1.tgz
  218. .. _`lxml 2.1.5`: lxml-2.1.5.tgz
  219. .. _`lxml 2.1.4`: lxml-2.1.4.tgz
  220. .. _`lxml 2.1.3`: lxml-2.1.3.tgz
  221. .. _`lxml 2.1.2`: lxml-2.1.2.tgz
  222. .. _`lxml 2.1.1`: lxml-2.1.1.tgz
  223. .. _`lxml 2.1`: lxml-2.1.tgz
  224. .. _`lxml 2.0.11`: lxml-2.0.11.tgz
  225. .. _`lxml 2.0.10`: lxml-2.0.10.tgz
  226. .. _`lxml 2.0.9`: lxml-2.0.9.tgz
  227. .. _`lxml 2.0.8`: lxml-2.0.8.tgz
  228. .. _`lxml 2.0.7`: lxml-2.0.7.tgz
  229. .. _`lxml 2.0.6`: lxml-2.0.6.tgz
  230. .. _`lxml 2.0.5`: lxml-2.0.5.tgz
  231. .. _`lxml 2.0.4`: lxml-2.0.4.tgz
  232. .. _`lxml 2.0.3`: lxml-2.0.3.tgz
  233. .. _`lxml 2.0.2`: lxml-2.0.2.tgz
  234. .. _`lxml 2.0.1`: lxml-2.0.1.tgz
  235. .. _`lxml 2.0`: lxml-2.0.tgz
  236. .. _`lxml 1.3.6`: lxml-1.3.6.tgz
  237. .. _`lxml 1.3.5`: lxml-1.3.5.tgz
  238. .. _`lxml 1.3.4`: lxml-1.3.4.tgz
  239. .. _`lxml 1.3.3`: lxml-1.3.3.tgz
  240. .. _`lxml 1.3.2`: lxml-1.3.2.tgz
  241. .. _`lxml 1.3`: lxml-1.3.tgz
  242. .. _`lxml 1.2.1`: lxml-1.2.1.tgz
  243. .. _`lxml 1.2`: lxml-1.2.tgz
  244. .. _`lxml 1.1.2`: lxml-1.1.2.tgz
  245. .. _`lxml 1.1.1`: lxml-1.1.1.tgz
  246. .. _`lxml 1.1`: lxml-1.1.tgz
  247. .. _`lxml 1.0.4`: lxml-1.0.4.tgz
  248. .. _`lxml 1.0.3`: lxml-1.0.3.tgz
  249. .. _`lxml 1.0.2`: lxml-1.0.2.tgz
  250. .. _`lxml 1.0.1`: lxml-1.0.1.tgz
  251. .. _`lxml 1.0`: lxml-1.0.tgz
  252. .. _`lxml 0.9.2`: lxml-0.9.2.tgz
  253. .. _`lxml 0.9.1`: lxml-0.9.1.tgz
  254. .. _`lxml 0.9`: lxml-0.9.tgz
  255. .. _`lxml 0.8`: lxml-0.8.tgz
  256. .. _`lxml 0.7`: lxml-0.7.tgz
  257. .. _`lxml 0.6`: lxml-0.6.tgz
  258. .. _`lxml 0.5.1`: lxml-0.5.1.tgz
  259. .. _`lxml 0.5`: lxml-0.5.tgz
  260. .. _`changes for 2.2.2`: changes-2.2.2.html
  261. .. _`changes for 2.2.1`: changes-2.2.1.html
  262. .. _`changes for 2.2`: changes-2.2.html
  263. .. _`changes for 2.2beta4`: changes-2.2beta4.html
  264. .. _`changes for 2.2beta3`: changes-2.2beta3.html
  265. .. _`changes for 2.2beta2`: changes-2.2beta2.html
  266. .. _`changes for 2.2beta1`: changes-2.2beta1.html
  267. .. _`changes for 2.2alpha1`: changes-2.2alpha1.html
  268. .. _`changes for 2.1.5`: changes-2.1.5.html
  269. .. _`changes for 2.1.4`: changes-2.1.4.html
  270. .. _`changes for 2.1.3`: changes-2.1.3.html
  271. .. _`changes for 2.1.2`: changes-2.1.2.html
  272. .. _`changes for 2.1.1`: changes-2.1.1.html
  273. .. _`changes for 2.1`: changes-2.1.html
  274. .. _`changes for 2.0.11`: changes-2.0.11.html
  275. .. _`changes for 2.0.10`: changes-2.0.10.html
  276. .. _`changes for 2.0.9`: changes-2.0.9.html
  277. .. _`changes for 2.0.8`: changes-2.0.8.html
  278. .. _`changes for 2.0.7`: changes-2.0.7.html
  279. .. _`changes for 2.0.6`: changes-2.0.6.html
  280. .. _`changes for 2.0.5`: changes-2.0.5.html
  281. .. _`changes for 2.0.4`: changes-2.0.4.html
  282. .. _`changes for 2.0.3`: changes-2.0.3.html
  283. .. _`changes for 2.0.2`: changes-2.0.2.html
  284. .. _`changes for 2.0.1`: changes-2.0.1.html
  285. .. _`changes for 2.0`: changes-2.0.html
  286. .. _`changes for 1.3.6`: changes-1.3.6.html
  287. .. _`changes for 1.3.5`: changes-1.3.5.html
  288. .. _`changes for 1.3.4`: changes-1.3.4.html
  289. .. _`changes for 1.3.3`: changes-1.3.3.html
  290. .. _`changes for 1.3.2`: changes-1.3.2.html
  291. .. _`changes for 1.3.1`: changes-1.3.1.html
  292. .. _`changes for 1.3`: changes-1.3.html
  293. .. _`changes for 1.2.1`: changes-1.2.1.html
  294. .. _`changes for 1.2`: changes-1.2.html
  295. .. _`changes for 1.1.2`: changes-1.1.2.html
  296. .. _`changes for 1.1.1`: changes-1.1.1.html
  297. .. _`changes for 1.1`: changes-1.1.html
  298. .. _`changes for 1.0.4`: changes-1.0.4.html
  299. .. _`changes for 1.0.3`: changes-1.0.3.html
  300. .. _`changes for 1.0.2`: changes-1.0.2.html
  301. .. _`changes for 1.0.1`: changes-1.0.1.html
  302. .. _`changes for 1.0`: changes-1.0.html
  303. .. _`changes for 0.9.2`: changes-0.9.2.html
  304. .. _`changes for 0.9.1`: changes-0.9.1.html
  305. .. _`changes for 0.9`: changes-0.9.html
  306. .. _`changes for 0.8`: changes-0.8.html
  307. .. _`changes for 0.7`: changes-0.7.html
  308. .. _`changes for 0.6`: changes-0.6.html
  309. .. _`changes for 0.5.1`: changes-0.5.1.html