libxml2macro

The libxml2macro tool and accompanying libraries (libxml2dom.macrolib) provide and experimental mechanism for writing normal DOM-style code (with node objects) and being able to transform such code into direct calls and accesses to the low-level libxml2mod API. Since libxml2dom now makes use of these libraries, and since the objects created at the libxml2dom level do not necessarily introduce a huge time or memory overhead, this mechanism is now more an experimental curiosity than anything of practical use. Moreover, the generated code does not attempt to clean up after libxml2, potentially introducing memory leaks into programs.

Using libxml2macro

The libxml2macro approach is as follows:

A description of the process is given in the README.txt file within the source code distribution. However, what libxml2macro does is to take code like this...

for my_node in my_element.childNodes:
if my_node.nodeType == TEXT_NODE:
print my_node.nodeValue

...and to transform it into something more or less like this (although in practice the actual libxml2mod calls are provided in a library, although more aggressive transformations could result in something actually like this):

for my_node in libxml2mod.children(my_element):
if libxml2mod.type(my_node) == "text":
print libxml2mod.xmlNodeGetContent(my_node)

The result is that developers can still write DOM-style code but not be penalised for the object-related overhead that such an approach typically incurs.