# HG changeset patch # User Paul Boddie # Date 1219696219 -7200 # Node ID d735943d4c3de16bad31f6039f8de87da31649f5 # Parent bfbf805a46362e26f803b754dc41acc2ff777bd4 Fixed the ownerElement of attribute nodes created using get_node (such as those appearing in XPath results). diff -r bfbf805a4636 -r d735943d4c3d libxml2dom/__init__.py --- a/libxml2dom/__init__.py Fri Jun 20 21:47:22 2008 +0200 +++ b/libxml2dom/__init__.py Mon Aug 25 22:30:19 2008 +0200 @@ -59,10 +59,21 @@ # Factory functions. def get_node(self, _node, context_node): + + # Return the existing document. + if Node_nodeType(_node) == context_node.DOCUMENT_NODE: return context_node.ownerDocument + + # Return an attribute using the parent of the attribute as the owner + # element. + elif Node_nodeType(_node) == context_node.ATTRIBUTE_NODE: - return Attribute(_node, self, context_node.ownerDocument, context_node) + return Attribute(_node, self, context_node.ownerDocument, + self.get_node(Node_parentNode(_node), context_node)) + + # Return other nodes. + else: return Node(_node, self, context_node.ownerDocument)