1 May 20:28
Re: Custom Elements question
From: Stefan Behnel <stefan_ml <at> behnel.de>
Subject: Re: Custom Elements question
Newsgroups: gmane.comp.python.lxml.devel
Date: 2008-05-01 18:28:12 GMT
Subject: Re: Custom Elements question
Newsgroups: gmane.comp.python.lxml.devel
Date: 2008-05-01 18:28:12 GMT
Hi,
Alex Klizhentas wrote:
> 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
That's because SubElement() does not call .append().
> 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!
As expected, as you call .append() explicitly here.
> and overriding
> def makeelement(self, tag, attrib):
> return Node(tag, attrib)
>
> in the NodeBase just does not help,
SubElement() does not call .makeelement() either. It's implemented in plain C.
Could you explain a bit why you want to do this and how your .append() differs
from the normal append code?
Stefan
RSS Feed