Thanks for the comments,<br><br>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.<br><br>That's why I'm going to override the ElementBase members so that they will notify observers on the certain actions performed. <br>
<br>Everything works fine, except this usefult SubElement function that did not work as expected, now you've clarified the things,<br><br>Thanks<br>Alex<br><br><div class="gmail_quote">2008/5/1 Stefan Behnel <<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>>:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<div class="Ih2E3d"><br>
Alex Klizhentas wrote:<br>
> I've extended the ElementBase object using the approach described in the<br>
> tutorial, but SubElement does not work as desired:<br>
><br>
> class NodeBase(etree.ElementBase):<br>
> def append(self,child):<br>
> print "aaa"<br>
> return etree.ElementBase.append(self,child)<br>
><br>
> etree.SubElement(root,"child") #no "aaa" printed<br>
<br>
</div>That's because SubElement() does not call .append().<br>
<div class="Ih2E3d"><br>
<br>
> OK, but when taking your code to the module:<br>
><br>
> def SubElement(parent, tag, attrib={}, **extra):<br>
> attrib = attrib.copy()<br>
> attrib.update(extra)<br>
> element = parent.makeelement(tag, attrib)<br>
> parent.append(element)<br>
> return element<br>
><br>
> SubElement(root,"child") # "aaa" is here!<br>
<br>
</div>As expected, as you call .append() explicitly here.<br>
<div class="Ih2E3d"><br>
<br>
> and overriding<br>
> def makeelement(self, tag, attrib):<br>
> return Node(tag, attrib)<br>
><br>
> in the NodeBase just does not help,<br>
<br>
</div>SubElement() does not call .makeelement() either. It's implemented in plain C.<br>
Could you explain a bit why you want to do this and how your .append() differs<br>
from the normal append code?<br>
<font color="#888888"><br>
Stefan<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Alex