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