Module pyclasslookup
A whole-tree Element class lookup scheme for lxml.etree.
This class lookup scheme allows access to the entire XML tree. To use
it, let a class inherit from PythonElementClassLookup and
re-implement the lookup(self, doc, root) method:
>>> from lxml import etree, pyclasslookup
>>>
>>> class MyElementClass(etree.ElementBase):
... honkey = True
...
>>> class MyLookup(pyclasslookup.PythonElementClassLookup):
... def lookup(self, doc, root):
... if root.tag == "sometag":
... return MyElementClass
... else:
... for child in root:
... if child.tag == "someothertag":
... return MyElementClass
...
... return None
See http://codespeak.net/lxml/element_classes.html