Thanks for the comments,<br><br>The idea behind this is to allow the XML tree to notify observers when it&#39;s contents are changed: the node is added, removed or moved.<br><br>That&#39;s why I&#39;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&#39;ve clarified the things,<br><br>Thanks<br>Alex<br><br><div class="gmail_quote">2008/5/1 Stefan Behnel &lt;<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>&gt;:<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>
&gt; I&#39;ve extended the ElementBase object using the approach described in the<br>
&gt; tutorial, but SubElement does not work as desired:<br>
&gt;<br>
&gt; class NodeBase(etree.ElementBase):<br>
&gt; &nbsp; &nbsp; &nbsp;def append(self,child):<br>
&gt; &nbsp;print &quot;aaa&quot;<br>
&gt; &nbsp;return etree.ElementBase.append(self,child)<br>
&gt;<br>
&gt; etree.SubElement(root,&quot;child&quot;) #no &quot;aaa&quot; printed<br>
<br>
</div>That&#39;s because SubElement() does not call .append().<br>
<div class="Ih2E3d"><br>
<br>
&gt; OK, but when taking your code to the module:<br>
&gt;<br>
&gt; def SubElement(parent, tag, attrib={}, **extra):<br>
&gt; &nbsp; &nbsp; attrib = attrib.copy()<br>
&gt; &nbsp; &nbsp; attrib.update(extra)<br>
&gt; &nbsp; &nbsp; element = parent.makeelement(tag, attrib)<br>
&gt; &nbsp; &nbsp; parent.append(element)<br>
&gt; &nbsp; &nbsp; return element<br>
&gt;<br>
&gt; SubElement(root,&quot;child&quot;) # &quot;aaa&quot; is here!<br>
<br>
</div>As expected, as you call .append() explicitly here.<br>
<div class="Ih2E3d"><br>
<br>
&gt; and overriding<br>
&gt; &nbsp; &nbsp; def makeelement(self, tag, attrib):<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; return Node(tag, attrib)<br>
&gt;<br>
&gt; in the NodeBase just does not help,<br>
<br>
</div>SubElement() does not call .makeelement() either. It&#39;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