1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>libxml2dom</title> 5 <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" /> 6 <link href="styles.css" rel="stylesheet" type="text/css" /> 7 </head> 8 9 <body> 10 <h1>libxml2dom</h1> 11 12 <p>The libxml2dom package provides a traditional DOM wrapper around the 13 Python bindings for <a href="http://www.xmlsoft.org">libxml2</a>. In contrast 14 to the libxml2 bindings, libxml2dom provides an API reminiscent of minidom, 15 pxdom and other Python-based and Python-related XML toolkits. Performance is 16 disappointing, given the typical high speed of libxml2 processing, but this 17 is to be expected since large numbers of Python objects are instantiated at 18 two levels of document tree representation. However, serialisation of 19 documents is much faster than many other toolkits because it can make direct 20 use of libxml2.</p> 21 22 <h2>Experiments</h2> 23 24 <p>The main libxml2dom package is relatively slow, even when compared to 25 Python-only XML toolkits, but previous experiments into source code analysis 26 suggested that with a slightly altered coding style, programs could be 27 transformed into a style which utilises the underlying libxml2mod API 28 directly; this API employs opaque handles which are exposed to Python but 29 which can only be investigated through the functions in the API. One 30 significant advantage of accessing the libxml2mod API directly is that the 31 libxml2 wrapper objects do not need to be instantiated, let alone the 32 additional libxml2dom wrapper objects, and the consequences are obvious: 33 reduced memory consumption and improved performance.</p> 34 35 <p>The libxml2macro approach is as follows:</p> 36 <ul> 37 <li>Write code using the PyXML-inspired DOM-style API, but giving node 38 variables and attributes a distinct prefix.</li> 39 <li>Run the supplied tool <code>libxml2macro.py</code> on the source 40 file.</li> 41 <li>Invoke the compiled module directly or import it into programs as 42 usual.</li> 43 </ul> 44 45 <p>A description of the process is given in the <code>README.txt</code> file 46 within the source code distribution. However, what libxml2macro does is to 47 take code like this...</p> 48 <pre>for my_node in my_element.childNodes: 49 if my_node.nodeType == TEXT_NODE: 50 print my_node.nodeValue</pre> 51 52 <p>...and to transform it into something more or less like this (although in 53 practice the actual libxml2mod calls are provided in a library, although more 54 aggressive transformations could result in something actually like this):</p> 55 <pre>for my_node in libxml2mod.children(my_element): 56 if libxml2mod.type(my_node) == "text": 57 print libxml2mod.xmlNodeGetContent(my_node)</pre> 58 59 <p>The result is that developers can still write DOM-style code but not be 60 penalised for the object-related overhead that such an approach typically 61 incurs.</p> 62 63 <h2>Copyright and Licence</h2> 64 65 <p>For reasons of consistency, libxml2dom uses the same MIT-style licence as 66 libxml2. See the file <code>COPYING.txt</code> in the <code>docs</code> 67 directory within the source code distribution.</p> 68 69 <h2>Installation</h2> 70 71 <p>Given the availability of libxml2, libxml2dom only needs to reside on the 72 PYTHONPATH and can be installed using the <code>setup.py</code> script 73 provided:</p> 74 <pre>python setup.py install</pre> 75 76 <h2>Dependencies and Installation Issues</h2> 77 78 <p>The following descriptions identify dependencies and describe appropriate 79 installation issues with each dependency:</p> 80 81 <h3>libxml2 2.6.16</h3> 82 83 <p>Building libxml2 from source and configuring the Python bindings can be 84 done as follows:</p> 85 <pre>cd libxml2-2.6.16 86 ./configure --with-python=/usr/local/bin/python 87 make</pre> 88 89 <p>If you are to use an installation of Python installed outside 90 <code>/usr/local</code> then specify the "prefix" accordingly. Install 91 (possibly as <code>root</code>) in the usual way:</p> 92 <pre>make install</pre> 93 94 <p>Previous releases of libxml2 in the 2.6 series may work, but some bugs 95 were observed with the previously recommended 2.6.0 and these may not have 96 been fixed until 2.6.16 or slightly earlier.</p> 97 98 <h4>Issues</h4> 99 100 <p>The <code>patches</code> directory in the source code distribution 101 contains a patch against libxml2 2.5.7 which resolves an issue exposed by 102 libxml2dom. Although it is recommended that later releases of libxml2 are 103 used instead, the source code distribution of libxml2 2.5.7 can be patched as 104 follows:</p> 105 <pre>patch -p0 < libxml2dom/patches/libxml2/libxml.c.diff</pre> 106 107 <p>The command should be run outside/above the <code>libxml2-2.5.7</code> 108 directory, and the stated path should be adjusted accordingly.</p> 109 110 <h3>Python 2.2</h3> 111 112 <p>Python releases from 2.2 onwards should be compatible with libxml2dom. The 113 principal requirement from such releases is the new-style class support which 114 permits the use of properties in the libxml2dom implementation, thus 115 simplifying the code somewhat.</p> 116 117 <h2>Changelog</h2> 118 119 <h3>New in libxml2dom 0.1.3 (Changes since libxml2dom 0.1.2)</h3> 120 <ul> 121 <li>Fixed createElement.</li> 122 <li>Introduced experimental libxml2macro tools, tests and libraries.</li> 123 </ul> 124 125 <h3>New in libxml2dom 0.1.2 (Changes since libxml2dom 0.1.1)</h3> 126 <ul> 127 <li>Fixed getAttributeNode and getAttributeNodeNS.</li> 128 <li>Added comment node creation.</li> 129 <li>Fixed empty namespace usage with elements and attributes.</li> 130 <li>Introduced usage of the libxml2 file and memory parsing features.</li> 131 <li>Introduced suppression of DTD retrieval and validation as the default 132 behaviour.</li> 133 <li>Added experimental XPath method support.</li> 134 </ul> 135 136 <h3>New in libxml2dom 0.1.1 (Changes since libxml2dom 0.1)</h3> 137 <ul> 138 <li>Fixed text node creation.</li> 139 <li>Fixed setAttributeNS.</li> 140 <li>Added encoding parameters to convenience methods.</li> 141 <li>Added the missing previousSibling property.</li> 142 <li>Added release number to the package.</li> 143 </ul> 144 </body> 145 </html>