[lxml-dev] Custom Elements question
Alex Klizhentas
klizhentas at gmail.com
Thu May 1 20:14:19 CEST 2008
Hi All,
Got a question:
I've extended the ElementBase object using the approach described in the
tutorial, but SubElement does not work as desired:
class NodeBase(etree.ElementBase):
def append(self,child):
print "aaa"
return etree.ElementBase.append(self,child)
etree.SubElement(root,"child") #no "aaa" printed
OK, but when taking your code to the module:
def SubElement(parent, tag, attrib={}, **extra):
attrib = attrib.copy()
attrib.update(extra)
element = parent.makeelement(tag, attrib)
parent.append(element)
return element
SubElement(root,"child") # "aaa" is here!
and overriding
def makeelement(self, tag, attrib):
return Node(tag, attrib)
in the NodeBase just does not help,
Any advice will be appreciated,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20080501/200b8175/attachment.htm
More information about the lxml-dev
mailing list