[XML-SIG] [Fwd: Re: [4suite] 4DOM bug in the new release]

Uche Ogbuji uche.ogbuji@fourthought.com
Tue, 25 Jul 2000 11:52:19 -0600


-------- Original Message --------
Subject: Re: [4suite] 4DOM bug in the new release
Date: Tue, 25 Jul 2000 11:34:46 -0600
From: "Jeremy J Kloth" <jeremy.kloth@fourthought.com>
To: "4suite mailing list" <4suite@dollar.fourthought.com>,"Alexandre
Fayolle" <alexandre.fayolle@free.fr>
References: <964526371.397d812328311@imp.free.fr>

> Hello,
>
> I think I've found a bug in 4DOM 0.10.2 : the ownerDocument is not set
properly
> on Attr when importing a node :
>
> from xml.dom.ext.reader import Sax2
> tree = """<document ><child foo='foo1' bar='bar1'/></document>"""
> if __name__ == '__main__':
>     doc1 = Sax2.FromXml(tree,None,0,1)
>     doc2 = Sax2.FromXml(tree,None,0,1)
>     child = doc1.documentElement
>     print "doc1 = " + str(doc1)
>     print "doc2 = " + str(doc2)
>     child2 = doc1.importNode(doc2.documentElement,1)
>     print "child2 owner = " + str(child2.ownerDocument)
>     print "child2 attr owner = " + \
> str(child2.firstChild.getAttributeNodeNS('','foo').ownerDocument)
>
>
> When I run the script, I get the followin output :
> doc1 = <XML Document at 135683560>
> doc2 = <XML Document at 135951328>
> child2 owner = <XML Document at 135683560>
> child2 attr owner = <XML Document at 135951328>
>
> I would have expected the attribute to have the same owner as the element
;o).
> Problem is, this breaks a *lot* of things. Try cloning child2, for
> instance...
>
>
> Alexandre Fayolle
> http://alexandre.fayolle.free.fr

Thanks for pointing that out to us.  Sorry for letting that one slip
through
our test net.
This will definitely be added to the tests.  The patch follows.

----------- start of patch --------------
diff -ur dom/Element.py patched/Element.py
--- dom/Element.py      Mon Jul 24 15:06:08 2000
+++ patched/Element.py  Tue Jul 25 11:29:09 2000
@@ -194,7 +194,7 @@
         for attr in attributes:
             # Attribute children are the value, so they're cloned
             # when the attribute is cloned, no need to go deep
-            newAttr = attr.cloneNode(0)
+            newAttr = attr.cloneNode(0, newOwner=self.ownerDocument)
             if self.ownerDocument._4dom_isNsAware:
                 self.attributes.setNamedItemNS(newAttr)
             else:
diff -ur dom/Node.py patched/Node.py
--- dom/Node.py Mon Jul 24 15:06:08 2000
+++ patched/Node.py     Tue Jul 25 11:28:38 2000
@@ -278,16 +278,16 @@
         else:
             state = {}

+        # Set when clone is used for import
+        if newOwner:
+            newNode._4dom_setOwnerDocument(newOwner)
+
         # Assign the current state to the copy
         setstate = getattr(newNode, '__setstate__', None)
         if setstate:
             setstate(state)
         else:
             newNode.__dict__.update(state)
-
-        # Set when clone is used for import
-        if newOwner:
-            newNode._4dom_setOwnerDocument(newOwner)

         # Copy the child nodes if deep
         if deep or self.nodeType == Node.ATTRIBUTE_NODE:
----------- end of patch --------------

--
Jeremy Kloth                        Consultant
jeremy.kloth@fourthought.com        (303)583-9900 x 102
Fourthought, Inc.                   http://www.fourthought.com
Software-engineering, knowledge-management, XML, CORBA, Linux, Python




_______________________________________________
4suite mailing list
4suite@lists.fourthought.com
http://lists.fourthought.com/mailman/listinfo/4suite