Upload Tizen:Base source
[toolchains/python-lxml.git] / doc / html / lxml-source-howto.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
6 <title>How to read the source of lxml</title>
7 <meta name="author" content="Stefan Behnel" />
8 <meta content="How to read and work on the source code of lxml" name="description" />
9 <meta content="lxml, XML, Cython, source code, develop, comprehend, understand" name="keywords" />
10 <link rel="stylesheet" href="style.css" type="text/css" />
11 </head>
12 <body>
13 <div class="document" id="how-to-read-the-source-of-lxml">
14 <div class="sidemenu"><ul id="lxml-section"><li><span class="section title">lxml</span><ul class="menu foreign" id="index-menu"><li class="menu title"><a href="index.html">lxml</a><ul class="submenu"><li class="menu item"><a href="index.html#introduction">Introduction</a></li><li class="menu item"><a href="index.html#documentation">Documentation</a></li><li class="menu item"><a href="index.html#download">Download</a></li><li class="menu item"><a href="index.html#mailing-list">Mailing list</a></li><li class="menu item"><a href="index.html#bug-tracker">Bug tracker</a></li><li class="menu item"><a href="index.html#license">License</a></li><li class="menu item"><a href="index.html#old-versions">Old Versions</a></li></ul></li></ul><ul class="menu foreign" id="intro-menu"><li class="menu title"><a href="intro.html">Why lxml?</a><ul class="submenu"><li class="menu item"><a href="intro.html#motto">Motto</a></li><li class="menu item"><a href="intro.html#aims">Aims</a></li></ul></li></ul><ul class="menu foreign" id="installation-menu"><li class="menu title"><a href="installation.html">Installing lxml</a><ul class="submenu"><li class="menu item"><a href="installation.html#requirements">Requirements</a></li><li class="menu item"><a href="installation.html#installation">Installation</a></li><li class="menu item"><a href="installation.html#building-lxml-from-sources">Building lxml from sources</a></li><li class="menu item"><a href="installation.html#ms-windows">MS Windows</a></li><li class="menu item"><a href="installation.html#macos-x">MacOS-X</a></li></ul></li></ul><ul class="menu foreign" id="lxml2-menu"><li class="menu title"><a href="lxml2.html">What's new in lxml 2.0?</a><ul class="submenu"><li class="menu item"><a href="lxml2.html#changes-in-etree-and-objectify">Changes in etree and objectify</a></li><li class="menu item"><a href="lxml2.html#new-modules">New modules</a></li></ul></li></ul><ul class="menu foreign" id="performance-menu"><li class="menu title"><a href="performance.html">Benchmarks and Speed</a><ul class="submenu"><li class="menu item"><a href="performance.html#general-notes">General notes</a></li><li class="menu item"><a href="performance.html#how-to-read-the-timings">How to read the timings</a></li><li class="menu item"><a href="performance.html#parsing-and-serialising">Parsing and Serialising</a></li><li class="menu item"><a href="performance.html#the-elementtree-api">The ElementTree API</a></li><li class="menu item"><a href="performance.html#xpath">XPath</a></li><li class="menu item"><a href="performance.html#a-longer-example">A longer example</a></li><li class="menu item"><a href="performance.html#lxml-objectify">lxml.objectify</a></li></ul></li></ul><ul class="menu foreign" id="compatibility-menu"><li class="menu title"><a href="compatibility.html">ElementTree compatibility of lxml.etree</a></li></ul><ul class="menu foreign" id="FAQ-menu"><li class="menu title"><a href="FAQ.html">lxml FAQ - Frequently Asked Questions</a><ul class="submenu"><li class="menu item"><a href="FAQ.html#general-questions">General Questions</a></li><li class="menu item"><a href="FAQ.html#installation">Installation</a></li><li class="menu item"><a href="FAQ.html#contributing">Contributing</a></li><li class="menu item"><a href="FAQ.html#bugs">Bugs</a></li><li class="menu item"><a href="FAQ.html#threading">Threading</a></li><li class="menu item"><a href="FAQ.html#parsing-and-serialisation">Parsing and Serialisation</a></li><li class="menu item"><a href="FAQ.html#xpath-and-document-traversal">XPath and Document Traversal</a></li></ul></li></ul></li></ul><ul id="Developing with lxml-section"><li><span class="section title">Developing with lxml</span><ul class="menu foreign" id="tutorial-menu"><li class="menu title"><a href="tutorial.html">The lxml.etree Tutorial</a><ul class="submenu"><li class="menu item"><a href="tutorial.html#the-element-class">The Element class</a></li><li class="menu item"><a href="tutorial.html#the-elementtree-class">The ElementTree class</a></li><li class="menu item"><a href="tutorial.html#parsing-from-strings-and-files">Parsing from strings and files</a></li><li class="menu item"><a href="tutorial.html#namespaces">Namespaces</a></li><li class="menu item"><a href="tutorial.html#the-e-factory">The E-factory</a></li><li class="menu item"><a href="tutorial.html#elementpath">ElementPath</a></li></ul></li></ul><ul class="menu foreign" id="api index-menu"><li class="menu title"><a href="api/index.html">API reference</a></li></ul><ul class="menu foreign" id="api-menu"><li class="menu title"><a href="api.html">APIs specific to lxml.etree</a><ul class="submenu"><li class="menu item"><a href="api.html#lxml-etree">lxml.etree</a></li><li class="menu item"><a href="api.html#other-element-apis">Other Element APIs</a></li><li class="menu item"><a href="api.html#trees-and-documents">Trees and Documents</a></li><li class="menu item"><a href="api.html#iteration">Iteration</a></li><li class="menu item"><a href="api.html#error-handling-on-exceptions">Error handling on exceptions</a></li><li class="menu item"><a href="api.html#error-logging">Error logging</a></li><li class="menu item"><a href="api.html#serialisation">Serialisation</a></li><li class="menu item"><a href="api.html#cdata">CDATA</a></li><li class="menu item"><a href="api.html#xinclude-and-elementinclude">XInclude and ElementInclude</a></li><li class="menu item"><a href="api.html#write-c14n-on-elementtree">write_c14n on ElementTree</a></li></ul></li></ul><ul class="menu foreign" id="parsing-menu"><li class="menu title"><a href="parsing.html">Parsing XML and HTML with lxml</a><ul class="submenu"><li class="menu item"><a href="parsing.html#parsers">Parsers</a></li><li class="menu item"><a href="parsing.html#the-target-parser-interface">The target parser interface</a></li><li class="menu item"><a href="parsing.html#the-feed-parser-interface">The feed parser interface</a></li><li class="menu item"><a href="parsing.html#iterparse-and-iterwalk">iterparse and iterwalk</a></li><li class="menu item"><a href="parsing.html#python-unicode-strings">Python unicode strings</a></li></ul></li></ul><ul class="menu foreign" id="validation-menu"><li class="menu title"><a href="validation.html">Validation with lxml</a><ul class="submenu"><li class="menu item"><a href="validation.html#validation-at-parse-time">Validation at parse time</a></li><li class="menu item"><a href="validation.html#dtd">DTD</a></li><li class="menu item"><a href="validation.html#relaxng">RelaxNG</a></li><li class="menu item"><a href="validation.html#xmlschema">XMLSchema</a></li><li class="menu item"><a href="validation.html#schematron">Schematron</a></li></ul></li></ul><ul class="menu foreign" id="xpathxslt-menu"><li class="menu title"><a href="xpathxslt.html">XPath and XSLT with lxml</a><ul class="submenu"><li class="menu item"><a href="xpathxslt.html#xpath">XPath</a></li><li class="menu item"><a href="xpathxslt.html#xslt">XSLT</a></li></ul></li></ul><ul class="menu foreign" id="objectify-menu"><li class="menu title"><a href="objectify.html">lxml.objectify</a><ul class="submenu"><li class="menu item"><a href="objectify.html#the-lxml-objectify-api">The lxml.objectify API</a></li><li class="menu item"><a href="objectify.html#asserting-a-schema">Asserting a Schema</a></li><li class="menu item"><a href="objectify.html#objectpath">ObjectPath</a></li><li class="menu item"><a href="objectify.html#python-data-types">Python data types</a></li><li class="menu item"><a href="objectify.html#how-data-types-are-matched">How data types are matched</a></li><li class="menu item"><a href="objectify.html#what-is-different-from-lxml-etree">What is different from lxml.etree?</a></li></ul></li></ul><ul class="menu foreign" id="lxmlhtml-menu"><li class="menu title"><a href="lxmlhtml.html">lxml.html</a><ul class="submenu"><li class="menu item"><a href="lxmlhtml.html#parsing-html">Parsing HTML</a></li><li class="menu item"><a href="lxmlhtml.html#html-element-methods">HTML Element Methods</a></li><li class="menu item"><a href="lxmlhtml.html#running-html-doctests">Running HTML doctests</a></li><li class="menu item"><a href="lxmlhtml.html#creating-html-with-the-e-factory">Creating HTML with the E-factory</a></li><li class="menu item"><a href="lxmlhtml.html#working-with-links">Working with links</a></li><li class="menu item"><a href="lxmlhtml.html#forms">Forms</a></li><li class="menu item"><a href="lxmlhtml.html#cleaning-up-html">Cleaning up HTML</a></li><li class="menu item"><a href="lxmlhtml.html#html-diff">HTML Diff</a></li><li class="menu item"><a href="lxmlhtml.html#examples">Examples</a></li></ul></li></ul><ul class="menu foreign" id="cssselect-menu"><li class="menu title"><a href="cssselect.html">lxml.cssselect</a><ul class="submenu"><li class="menu item"><a href="cssselect.html#the-cssselector-class">The CSSSelector class</a></li><li class="menu item"><a href="cssselect.html#css-selectors">CSS Selectors</a></li><li class="menu item"><a href="cssselect.html#namespaces">Namespaces</a></li><li class="menu item"><a href="cssselect.html#limitations">Limitations</a></li></ul></li></ul><ul class="menu foreign" id="elementsoup-menu"><li class="menu title"><a href="elementsoup.html">BeautifulSoup Parser</a><ul class="submenu"><li class="menu item"><a href="elementsoup.html#parsing-with-the-soupparser">Parsing with the soupparser</a></li><li class="menu item"><a href="elementsoup.html#entity-handling">Entity handling</a></li><li class="menu item"><a href="elementsoup.html#using-soupparser-as-a-fallback">Using soupparser as a fallback</a></li><li class="menu item"><a href="elementsoup.html#using-only-the-encoding-detection">Using only the encoding detection</a></li></ul></li></ul><ul class="menu foreign" id="html5parser-menu"><li class="menu title"><a href="html5parser.html">html5lib Parser</a><ul class="submenu"><li class="menu item"><a href="html5parser.html#differences-to-regular-html-parsing">Differences to regular HTML parsing</a></li><li class="menu item"><a href="html5parser.html#function-reference">Function Reference</a></li></ul></li></ul></li></ul><ul id="Extending lxml-section"><li><span class="section title">Extending lxml</span><ul class="menu foreign" id="resolvers-menu"><li class="menu title"><a href="resolvers.html">Document loading and URL resolving</a><ul class="submenu"><li class="menu item"><a href="resolvers.html#uri-resolvers">URI Resolvers</a></li><li class="menu item"><a href="resolvers.html#document-loading-in-context">Document loading in context</a></li><li class="menu item"><a href="resolvers.html#i-o-access-control-in-xslt">I/O access control in XSLT</a></li></ul></li></ul><ul class="menu foreign" id="extensions-menu"><li class="menu title"><a href="extensions.html">Python extensions for XPath and XSLT</a><ul class="submenu"><li class="menu item"><a href="extensions.html#xpath-extension-functions">XPath Extension functions</a></li><li class="menu item"><a href="extensions.html#xslt-extension-elements">XSLT extension elements</a></li></ul></li></ul><ul class="menu foreign" id="element classes-menu"><li class="menu title"><a href="element_classes.html">Using custom Element classes in lxml</a><ul class="submenu"><li class="menu item"><a href="element_classes.html#background-on-element-proxies">Background on Element proxies</a></li><li class="menu item"><a href="element_classes.html#element-initialization">Element initialization</a></li><li class="menu item"><a href="element_classes.html#setting-up-a-class-lookup-scheme">Setting up a class lookup scheme</a></li><li class="menu item"><a href="element_classes.html#generating-xml-with-custom-classes">Generating XML with custom classes</a></li><li class="menu item"><a href="element_classes.html#implementing-namespaces">Implementing namespaces</a></li></ul></li></ul><ul class="menu foreign" id="sax-menu"><li class="menu title"><a href="sax.html">Sax support</a><ul class="submenu"><li class="menu item"><a href="sax.html#building-a-tree-from-sax-events">Building a tree from SAX events</a></li><li class="menu item"><a href="sax.html#producing-sax-events-from-an-elementtree-or-element">Producing SAX events from an ElementTree or Element</a></li><li class="menu item"><a href="sax.html#interfacing-with-pulldom-minidom">Interfacing with pulldom/minidom</a></li></ul></li></ul><ul class="menu foreign" id="capi-menu"><li class="menu title"><a href="capi.html">The public C-API of lxml.etree</a><ul class="submenu"><li class="menu item"><a href="capi.html#writing-external-modules-in-cython">Writing external modules in Cython</a></li><li class="menu item"><a href="capi.html#writing-external-modules-in-c">Writing external modules in C</a></li></ul></li></ul></li></ul><ul id="Developing lxml-section"><li><span class="section title">Developing lxml</span><ul class="menu foreign" id="build-menu"><li class="menu title"><a href="build.html">How to build lxml from source</a><ul class="submenu"><li class="menu item"><a href="build.html#cython">Cython</a></li><li class="menu item"><a href="build.html#subversion">Subversion</a></li><li class="menu item"><a href="build.html#setuptools">Setuptools</a></li><li class="menu item"><a href="build.html#running-the-tests-and-reporting-errors">Running the tests and reporting errors</a></li><li class="menu item"><a href="build.html#building-an-egg">Building an egg</a></li><li class="menu item"><a href="build.html#building-lxml-on-macos-x">Building lxml on MacOS-X</a></li><li class="menu item"><a href="build.html#static-linking-on-windows">Static linking on Windows</a></li><li class="menu item"><a href="build.html#building-debian-packages-from-svn-sources">Building Debian packages from SVN sources</a></li></ul></li></ul><ul class="menu foreign" id="lxml source howto-menu"><li class="menu title"><a href="lxml-source-howto.html">How to read the source of lxml</a><ul class="submenu"><li class="menu item"><a href="lxml-source-howto.html#what-is-cython">What is Cython?</a></li><li class="menu item"><a href="lxml-source-howto.html#where-to-start">Where to start?</a></li><li class="menu item"><a href="lxml-source-howto.html#lxml-etree">lxml.etree</a></li><li class="menu item"><a href="lxml-source-howto.html#python-modules">Python modules</a></li><li class="menu item"><a href="lxml-source-howto.html#lxml-objectify">lxml.objectify</a></li><li class="menu item"><a href="lxml-source-howto.html#lxml-html">lxml.html</a></li></ul></li></ul><ul class="menu foreign" id="changes 2 2 3-menu"><li class="menu title"><a href="changes-2.2.3.html">Release Changelog</a></li></ul><ul class="menu foreign" id="credits-menu"><li class="menu title"><a href="credits.html">Credits</a><ul class="submenu"><li class="menu item"><a href="credits.html#main-contributors">Main contributors</a></li><li class="menu item"><a href="credits.html#special-thanks-goes-to">Special thanks goes to:</a></li></ul></li></ul></li></ul></div><h1 class="title">How to read the source of lxml</h1>
15 <table class="docinfo" frame="void" rules="none">
16 <col class="docinfo-name" />
17 <col class="docinfo-content" />
18 <tbody valign="top">
19 <tr><th class="docinfo-name">Author:</th>
20 <td>Stefan Behnel</td></tr>
21 </tbody>
22 </table>
23 <p>This document describes how to read the source code of <a class="reference external" href="http://codespeak.net/lxml/">lxml</a> and how
24 to start working on it.  You might also be interested in the companion
25 document that describes <a class="reference external" href="build.html">how to build lxml from sources</a>.</p>
26 <div class="contents topic" id="contents">
27 <p class="topic-title first">Contents</p>
28 <ul class="simple">
29 <li><a class="reference internal" href="#what-is-cython" id="id1">What is Cython?</a></li>
30 <li><a class="reference internal" href="#where-to-start" id="id2">Where to start?</a><ul>
31 <li><a class="reference internal" href="#concepts" id="id3">Concepts</a></li>
32 <li><a class="reference internal" href="#the-documentation" id="id4">The documentation</a></li>
33 </ul>
34 </li>
35 <li><a class="reference internal" href="#lxml-etree" id="id5">lxml.etree</a></li>
36 <li><a class="reference internal" href="#python-modules" id="id6">Python modules</a></li>
37 <li><a class="reference internal" href="#lxml-objectify" id="id7">lxml.objectify</a></li>
38 <li><a class="reference internal" href="#lxml-html" id="id8">lxml.html</a></li>
39 </ul>
40 </div>
41 <div class="section" id="what-is-cython">
42 <h1>What is Cython?</h1>
43 <p><a class="reference external" href="http://cython.org/">Cython</a> is the language that lxml is written in.  It is a very
44 Python-like language that was specifically designed for writing Python
45 extension modules.</p>
46 <p>The reason why Cython (or actually its predecessor <a class="reference external" href="http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/">Pyrex</a> at the time)
47 was chosen as an implementation language for lxml, is that it makes it
48 very easy to interface with both the Python world and external C code.
49 Cython generates all the necessary glue code for the Python API,
50 including Python types, calling conventions and reference counting.
51 On the other side of the table, calling into C code is not more than
52 declaring the signature of the function and maybe some variables as
53 being C types, pointers or structs, and then calling it.  The rest of
54 the code is just plain Python code.</p>
55 <p>The Cython language is so close to Python that the Cython compiler can
56 actually compile many, many Python programs to C without major
57 modifications.  But the real speed gains of a C compilation come from
58 type annotations that were added to the language and that allow Cython
59 to generate very efficient C code.</p>
60 <p>Even if you are not familiar with Cython, you should keep in mind that
61 a slow implementation of a feature is better than none.  So, if you
62 want to contribute and have an idea what code you want to write, feel
63 free to start with a pure Python implementation.  Chances are, if you
64 get the change officially accepted and integrated, others will take
65 the time to optimise it so that it runs fast in Cython.</p>
66 </div>
67 <div class="section" id="where-to-start">
68 <h1>Where to start?</h1>
69 <p>First of all, read <a class="reference external" href="build.html">how to build lxml from sources</a> to learn how to
70 retrieve the source code from the Subversion repository and how to
71 build it.  The source code lives in the subdirectory <tt class="docutils literal"><span class="pre">src</span></tt> of the
72 checkout.</p>
73 <p>The main extension modules in lxml are <tt class="docutils literal"><span class="pre">lxml.etree</span></tt> and
74 <tt class="docutils literal"><span class="pre">lxml.objectify</span></tt>.  All main modules have the file extension
75 <tt class="docutils literal"><span class="pre">.pyx</span></tt>, which shows the descendence from Pyrex.  As usual in Python,
76 the main files start with a short description and a couple of imports.
77 Cython distinguishes between the run-time <tt class="docutils literal"><span class="pre">import</span></tt> statement (as
78 known from Python) and the compile-time <tt class="docutils literal"><span class="pre">cimport</span></tt> statement, which
79 imports C declarations, either from external libraries or from other
80 Cython modules.</p>
81 <div class="section" id="concepts">
82 <h2>Concepts</h2>
83 <p>lxml's tree API is based on proxy objects.  That means, every Element
84 object (or rather <tt class="docutils literal"><span class="pre">_Element</span></tt> object) is a proxy for a libxml2 node
85 structure.  The class declaration is (mainly):</p>
86 <pre class="literal-block">
87 cdef class _Element:
88     cdef _Document _doc
89     cdef xmlNode* _c_node
90 </pre>
91 <p>It is a naming convention that C variables and C level class members
92 that are passed into libxml2 start with a prefixed <tt class="docutils literal"><span class="pre">c_</span></tt> (commonly
93 libxml2 struct pointers), and that C level class members are prefixed
94 with an underscore.  So you will often see names like <tt class="docutils literal"><span class="pre">c_doc</span></tt> for an
95 <tt class="docutils literal"><span class="pre">xmlDoc*</span></tt> variable (or <tt class="docutils literal"><span class="pre">c_node</span></tt> for an <tt class="docutils literal"><span class="pre">xmlNode*</span></tt>), or the above
96 <tt class="docutils literal"><span class="pre">_c_node</span></tt> for a class member that points to an <tt class="docutils literal"><span class="pre">xmlNode</span></tt> struct
97 (or <tt class="docutils literal"><span class="pre">_c_doc</span></tt> for an <tt class="docutils literal"><span class="pre">xmlDoc*</span></tt>).</p>
98 <p>It is important to know that every proxy in lxml has a factory
99 function that properly sets up C level members.  Proxy objects must
100 <em>never</em> be instantiated outside of that factory.  For example, to
101 instantiate an _Element object or its subclasses, you must always call
102 its factory function:</p>
103 <pre class="literal-block">
104 cdef xmlNode* c_node
105 cdef _Document doc
106 cdef _Element element
107 ...
108 element = _elementFactory(doc, c_node)
109 </pre>
110 <p>A good place to see how this factory is used are the Element methods
111 <tt class="docutils literal"><span class="pre">getparent()</span></tt>, <tt class="docutils literal"><span class="pre">getnext()</span></tt> and <tt class="docutils literal"><span class="pre">getprevious()</span></tt>.</p>
112 </div>
113 <div class="section" id="the-documentation">
114 <h2>The documentation</h2>
115 <p>An important part of lxml is the documentation that lives in the
116 <tt class="docutils literal"><span class="pre">doc</span></tt> directory.  It describes a large part of the API and comprises
117 a lot of example code in the form of doctests.</p>
118 <p>The documentation is written in the <a class="reference external" href="http://docutils.sourceforge.net/rst.html">ReStructured Text</a> format, a
119 very powerful text markup language that looks almost like plain text.
120 It is part of the <a class="reference external" href="http://docutils.sourceforge.net/">docutils</a> package.</p>
121 <p>The project web site of <a class="reference external" href="http://codespeak.net/lxml/">lxml</a> is completely generated from these text
122 documents.  Even the side menu is just collected from the table of
123 contents that the ReST processor writes into each HTML page.
124 Obviously, we use lxml for this.</p>
125 <p>The easiest way to generate the HTML pages is by calling:</p>
126 <pre class="literal-block">
127 make html
128 </pre>
129 <p>This will call the script <tt class="docutils literal"><span class="pre">doc/mkhtml.py</span></tt> to run the ReST processor
130 on the files.  After generating an HTML page the script parses it back
131 in to build the side menu, and injects the complete menu into each
132 page at the very end.</p>
133 <p>Running the <tt class="docutils literal"><span class="pre">make</span></tt> command will also generate the API documentation
134 if you have <a class="reference external" href="http://epydoc.sourceforge.net/">epydoc</a> installed.  The epydoc package will import and
135 introspect the extension modules and also introspect and parse the
136 Python modules of lxml.  The aggregated information will then be
137 written out into an HTML documentation site.</p>
138 </div>
139 </div>
140 <div class="section" id="lxml-etree">
141 <h1>lxml.etree</h1>
142 <p>The main module, <tt class="docutils literal"><span class="pre">lxml.etree</span></tt>, is in the file <a class="reference external" href="http://codespeak.net/svn/lxml/trunk/src/lxml/lxml.etree.pyx">lxml.etree.pyx</a>.  It
143 implements the main functions and types of the ElementTree API, as
144 well as all the factory functions for proxies.  It is the best place
145 to start if you want to find out how a specific feature is
146 implemented.</p>
147 <p>At the very end of the file, it contains a series of <tt class="docutils literal"><span class="pre">include</span></tt>
148 statements that merge the rest of the implementation into the
149 generated C code.  Yes, you read right: no importing, no source file
150 namespacing, just plain good old include and a huge C code result of
151 more than 100,000 lines that we throw right into the C compiler.</p>
152 <p>The main include files are:</p>
153 <dl class="docutils">
154 <dt>apihelpers.pxi</dt>
155 <dd>Private C helper functions.  Except for the factory functions,
156 most of the little functions that are used all over the place are
157 defined here.  This includes things like reading out the text
158 content of a libxml2 tree node, checking input from the API level,
159 creating a new Element node or handling attribute values.  If you
160 want to work on the lxml code, you should keep these functions in
161 the back of your head, as they will definitely make your life
162 easier.</dd>
163 <dt>classlookup.pxi</dt>
164 <dd>Element class lookup mechanisms.  The main API and engines for
165 those who want to define custom Element classes and inject them
166 into lxml.</dd>
167 <dt>docloader.pxi</dt>
168 <dd>Support for custom document loaders.  Base class and registry for
169 custom document resolvers.</dd>
170 <dt>extensions.pxi</dt>
171 <dd>Infrastructure for extension functions in XPath/XSLT, including
172 XPath value conversion and function registration.</dd>
173 <dt>iterparse.pxi</dt>
174 <dd>Incremental XML parsing.  An iterator class that builds iterparse
175 events while parsing.</dd>
176 <dt>nsclasses.pxi</dt>
177 <dd>Namespace implementation and registry.  The registry and engine
178 for Element classes that use the ElementNamespaceClassLookup
179 scheme.</dd>
180 <dt>parser.pxi</dt>
181 <dd>Parsers for XML and HTML.  This is the main parser engine.  It's
182 the reason why you can parse a document from various sources in
183 two lines of Python code.  It's definitely not the right place to
184 start reading lxml's soure code.</dd>
185 <dt>parsertarget.pxi</dt>
186 <dd>An ElementTree compatible parser target implementation based on
187 the SAX2 interface of libxml2.</dd>
188 <dt>proxy.pxi</dt>
189 <dd>Very low-level functions for memory allocation/deallocation
190 and Element proxy handling.  Ignoring this for the beginning
191 will safe your head from exploding.</dd>
192 <dt>public-api.pxi</dt>
193 <dd>The set of C functions that are exported to other extension
194 modules at the C level.  For example, <tt class="docutils literal"><span class="pre">lxml.objectify</span></tt> makes use
195 of these.  See the <cite>C-level API</cite> documentation.</dd>
196 <dt>readonlytree.pxi</dt>
197 <dd>A separate read-only implementation of the Element API.  This is
198 used in places where non-intrusive access to a tree is required,
199 such as the <tt class="docutils literal"><span class="pre">PythonElementClassLookup</span></tt> or XSLT extension
200 elements.</dd>
201 <dt>saxparser.pxi</dt>
202 <dd>SAX-like parser interfaces as known from ElementTree's TreeBuilder.</dd>
203 <dt>serializer.pxi</dt>
204 <dd>XML output functions.  Basically everything that creates byte
205 sequences from XML trees.</dd>
206 <dt>xinclude.pxi</dt>
207 <dd>XInclude support.</dd>
208 <dt>xmlerror.pxi</dt>
209 <dd><p class="first">Error log handling.  All error messages that libxml2 generates
210 internally walk through the code in this file to end up in lxml's
211 Python level error logs.</p>
212 <p class="last">At the end of the file, you will find a long list of named error
213 codes.  It is generated from the libxml2 HTML documentation (using
214 lxml, of course).  See the script <tt class="docutils literal"><span class="pre">update-error-constants.py</span></tt>
215 for this.</p>
216 </dd>
217 <dt>xmlid.pxi</dt>
218 <dd>XMLID and IDDict, a dictionary-like way to find Elements by their
219 XML-ID attribute.</dd>
220 <dt>xpath.pxi</dt>
221 <dd>XPath evaluators.</dd>
222 <dt>xslt.pxi</dt>
223 <dd>XSL transformations, including the <tt class="docutils literal"><span class="pre">XSLT</span></tt> class, document lookup
224 handling and access control.</dd>
225 </dl>
226 <p>The different schema languages (DTD, RelaxNG, XML Schema and
227 Schematron) are implemented in the following include files:</p>
228 <ul class="simple">
229 <li>dtd.pxi</li>
230 <li>relaxng.pxi</li>
231 <li>schematron.pxi</li>
232 <li>xmlschema.pxi</li>
233 </ul>
234 </div>
235 <div class="section" id="python-modules">
236 <h1>Python modules</h1>
237 <p>The <tt class="docutils literal"><span class="pre">lxml</span></tt> package also contains a number of pure Python modules:</p>
238 <dl class="docutils">
239 <dt>builder.py</dt>
240 <dd>The E-factory and the ElementBuilder class.  These provide a
241 simple interface to XML tree generation.</dd>
242 <dt>cssselect.py</dt>
243 <dd>A CSS selector implementation based on XPath.  The main class is
244 called <tt class="docutils literal"><span class="pre">CSSSelector</span></tt>.</dd>
245 <dt>doctestcompare.py</dt>
246 <dd>A relaxed comparison scheme for XML/HTML markup in doctest.</dd>
247 <dt>ElementInclude.py</dt>
248 <dd>XInclude-like document inclusion, compatible with ElementTree.</dd>
249 <dt>_elementpath.py</dt>
250 <dd>XPath-like path language, compatible with ElementTree.</dd>
251 <dt>sax.py</dt>
252 <dd>SAX2 compatible interfaces to copy lxml trees from/to SAX compatible
253 tools.</dd>
254 <dt>usedoctest.py</dt>
255 <dd>Wrapper module for <tt class="docutils literal"><span class="pre">doctestcompare.py</span></tt> that simplifies its usage
256 from inside a doctest.</dd>
257 </dl>
258 </div>
259 <div class="section" id="lxml-objectify">
260 <h1>lxml.objectify</h1>
261 <p>A Cython implemented extension module that uses the public C-API of
262 lxml.etree.  It provides a Python object-like interface to XML trees.
263 The implementation resides in the file <a class="reference external" href="http://codespeak.net/svn/lxml/trunk/src/lxml/lxml.objectify.pyx">lxml.objectify.pyx</a>.</p>
264 </div>
265 <div class="section" id="lxml-html">
266 <h1>lxml.html</h1>
267 <p>A specialised toolkit for HTML handling, based on lxml.etree.  This is
268 implemented in pure Python.</p>
269 </div>
270 </div>
271 <div class="footer">
272 <hr class="footer" />
273 Generated on: 2009-10-30.
274
275 </div>
276 </body>
277 </html>