paulb@109 | 1 | Experiments
|
paulb@109 | 2 | -----------
|
paulb@109 | 3 |
|
paulb@109 | 4 | The libxml2macro.py program, along with the libxml2dom.macrolib package
|
paulb@109 | 5 | provide support for writing DOM-style code which is then translated to
|
paulb@109 | 6 | libxml2mod-style code before being compiled to normal Python modules. This
|
paulb@109 | 7 | special translation should eliminate the need for high-level wrapper objects
|
paulb@109 | 8 | in most cases as well as low-level libxml2 objects, since the actual compiled
|
paulb@109 | 9 | code will be using the libxml2mod functions directly.
|
paulb@109 | 10 |
|
paulb@109 | 11 | To use libxml2macro.py, first write your code using the typical PyXML DOM
|
paulb@109 | 12 | style, but make sure that you use a common prefix for all node variables and
|
paulb@109 | 13 | which is not used by any other kind of variable, and make sure that you do not
|
paulb@109 | 14 | re-use node variables to refer to other kinds of object. Here is an example of
|
paulb@109 | 15 | the coding style:
|
paulb@109 | 16 |
|
paulb@109 | 17 | # My module.
|
paulb@109 | 18 |
|
paulb@109 | 19 | import libxml2macro as my_
|
paulb@109 | 20 |
|
paulb@109 | 21 | def processing_function(my_document, some_args):
|
paulb@109 | 22 |
|
paulb@109 | 23 | # Perform actions on nodes:
|
paulb@109 | 24 |
|
paulb@109 | 25 | my_node = my_document.createElementNS("namespace", "some-name")
|
paulb@109 | 26 |
|
paulb@109 | 27 | # Perform actions on other data as normal:
|
paulb@109 | 28 |
|
paulb@109 | 29 | some_function(some_args)
|
paulb@109 | 30 |
|
paulb@109 | 31 | Then, run libxml2macro.py on the module like this (using tests/macrotest.py as
|
paulb@109 | 32 | an example):
|
paulb@109 | 33 |
|
paulb@109 | 34 | tools/libxml2macro.py tests/macrotest.py
|
paulb@109 | 35 |
|
paulb@109 | 36 | This produces a compiled module that can be imported into Python; for example:
|
paulb@109 | 37 |
|
paulb@109 | 38 | cd tests
|
paulb@109 | 39 | python
|
paulb@109 | 40 | import macrotest
|
paulb@109 | 41 |
|
paulb@109 | 42 | It should be possible to run the module directly; for example:
|
paulb@109 | 43 |
|
paulb@109 | 44 | python tests/macrotest.pyc
|
paulb@109 | 45 |
|
paulb@109 | 46 | Note that running the module using the source filename will probably result in
|
paulb@109 | 47 | the compiled module being overwritten and various errors being produced. So
|
paulb@109 | 48 | don't do that!
|