[XML-SIG] pDomlette and importNode
Alexandre Fayolle
Alexandre.Fayolle@logilab.fr
Fri, 21 Sep 2001 11:12:14 +0200 (CEST)
On Fri, 21 Sep 2001, Xhaus Main Account wrote:
> Thanks for the tips Alexander.
>
> However, from what I can see, pDomlette and cDomlette are not suitable for my
> needs due to incomplete DOM support (I'll briefly explain my app below).
>
> However, I do need support for "importNode". I can see that pDomlette does not
> have it, and I think cDomlette doesn't have it either (I checked by doing
> "strings cDomlettec.pyd | grep importNode". Am I wrong here?)
cDomlette is for now readonly, so it won't support importNode. pDomlette
does not. We needed this in Narval, as well as removeAttributeNS, so what
we do is add the methods dynamically to the class at start up. Now, I'm
pretty sure that if this is asked to the Fourthought people, they could
consider adding the method to pDomlette in the next release (and to
cDomlette which, I am told, should be read-write in the near future).
In the meantime, here's a snippet which adds importNode and
removeAttributeNS to pDomlette nodes:
-----------------8<-----------------------------
from Ft.Lib.pDomlette import Element,Document
def myremoveAttributeNS(self,nsURI,lname):
node = self.getAttributeNodeNS(nsURI,lname)
if node:
self.removeAttributeNode(node)
return
Element.removeAttributeNS = myremoveAttributeNS
def _changeowner(node,owner):
node.ownerDocument = owner
for a in node.attributes or []:
a.ownerDocument = owner
[_changeowner(c,owner) for c in node.childNodes or []]
def myimportNode(self,importedNode,deep=0):
try:
new_node = importedNode.cloneNode(deep)
_changeowner(new_node,self)
return new_node
except Exception,e:
print importedNode.__class__
raise e
Document.importNode = myimportNode
---------------------8<---------------------------
Alexandre Fayolle
--
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Narval, the first software agent available as free software (GPL).