paulb@20 | 1 | See docs/index.html for the libxml2dom documentation.
|
paulb@35 | 2 |
|
paulb@35 | 3 | Issues
|
paulb@35 | 4 | ------
|
paulb@35 | 5 |
|
paulb@35 | 6 | Use of importNode seems to cause some kind of memory issue, probably related
|
paulb@41 | 7 | to nodes being shared across documents. This was observed in libxml2 2.6.0 but
|
paulb@41 | 8 | appears to be fixed in libxml2 2.6.16.
|
paulb@50 | 9 |
|
paulb@50 | 10 | Even compared to minidom, importNode is very slow (even the
|
paulb@50 | 11 | libxml2dom.macrolib implementation, too). A way is needed to get libxml2 to do
|
paulb@50 | 12 | the node copying itself.
|
paulb@50 | 13 |
|
paulb@50 | 14 | Experiments
|
paulb@50 | 15 | -----------
|
paulb@50 | 16 |
|
paulb@50 | 17 | The libxml2macro.py program, along with the libxml2dom.macrolib package
|
paulb@50 | 18 | provide support for writing DOM-style code which is then translated to
|
paulb@59 | 19 | libxml2mod-style code before being compiled to normal Python modules. This
|
paulb@50 | 20 | special translation should eliminate the need for high-level wrapper objects
|
paulb@59 | 21 | in most cases as well as low-level libxml2 objects, since the actual compiled
|
paulb@59 | 22 | code will be using the libxml2mod functions directly.
|
paulb@59 | 23 |
|
paulb@59 | 24 | To use libxml2macro.py, first write your code using the typical PyXML DOM
|
paulb@59 | 25 | style, but make sure that you use a common prefix for all node variables and
|
paulb@59 | 26 | which is not used by any other kind of variable, and make sure that you do not
|
paulb@59 | 27 | re-use node variables to refer to other kinds of object. Here is an example of
|
paulb@59 | 28 | the coding style:
|
paulb@59 | 29 |
|
paulb@59 | 30 | # My module.
|
paulb@59 | 31 |
|
paulb@59 | 32 | import libxml2macro as my_
|
paulb@59 | 33 |
|
paulb@59 | 34 | def processing_function(my_document, some_args):
|
paulb@59 | 35 |
|
paulb@59 | 36 | # Perform actions on nodes:
|
paulb@59 | 37 |
|
paulb@59 | 38 | my_node = my_document.createElementNS("namespace", "some-name")
|
paulb@59 | 39 |
|
paulb@59 | 40 | # Perform actions on other data as normal:
|
paulb@59 | 41 |
|
paulb@59 | 42 | some_function(some_args)
|
paulb@59 | 43 |
|
paulb@59 | 44 | Then, run libxml2macro.py on the module like this (using tests/macrotest.py as
|
paulb@59 | 45 | an example):
|
paulb@59 | 46 |
|
paulb@59 | 47 | libxml2macro.py tests/macrotest.py
|
paulb@59 | 48 |
|
paulb@59 | 49 | This produces a compiled module that can be imported into Python; for example:
|
paulb@59 | 50 |
|
paulb@59 | 51 | cd tests
|
paulb@59 | 52 | python
|
paulb@59 | 53 | import macrotest
|
paulb@59 | 54 |
|
paulb@59 | 55 | It should be possible to run the module directly; for example:
|
paulb@59 | 56 |
|
paulb@59 | 57 | python tests/macrotest.pyc
|
paulb@59 | 58 |
|
paulb@59 | 59 | Note that running the module using the source filename will probably result in
|
paulb@59 | 60 | the compiled module being overwritten and various errors being produced. So
|
paulb@59 | 61 | don't do that!
|