1 May 21:11
Re: Custom Elements question
From: Alex Klizhentas <klizhentas <at> gmail.com>
Subject: Re: Custom Elements question
Newsgroups: gmane.comp.python.lxml.devel
Date: 2008-05-01 19:11:38 GMT
Subject: Re: Custom Elements question
Newsgroups: gmane.comp.python.lxml.devel
Date: 2008-05-01 19:11:38 GMT
Thanks for the comments,
The idea behind this is to allow the XML tree to notify observers when it's contents are changed: the node is added, removed or moved.
That's why I'm going to override the ElementBase members so that they will notify observers on the certain actions performed.
Everything works fine, except this usefult SubElement function that did not work as expected, now you've clarified the things,
Thanks
Alex
2008/5/1 Stefan Behnel <stefan_ml <at> behnel.de>:
Hi,That's because SubElement() does not call .append().
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
As expected, as you call .append() explicitly here.
> 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!
SubElement() does not call .makeelement() either. It's implemented in plain C.
> and overriding
> def makeelement(self, tag, attrib):
> return Node(tag, attrib)
>
> in the NodeBase just does not help,
Could you explain a bit why you want to do this and how your .append() differs
from the normal append code?
Stefan
--
Regards,
Alex
_______________________________________________ lxml-dev mailing list lxml-dev <at> codespeak.net http://codespeak.net/mailman/listinfo/lxml-dev
RSS Feed