[XML-SIG] node identity with libxml2

M.-A. Lemburg mal at egenix.com
Thu Jan 29 07:27:37 EST 2004


Daniel Veillard wrote:
> On Thu, Jan 29, 2004 at 11:40:21AM +0000, Matt Patterson wrote:
> 
>>Hello,
>>
>>I'm using libxml2 and I'm trying to determine the intersection of two 
>>lists of nodes, where each list is a leaf-to-root chain of ancestors. 
>>The lists do have a point of intersection.
>>
>>printing the trees shows this:
>>
>>tree1: [<xmlNode (start) object at 0x6d788>, <xmlNode (alpha) object at 
>>0x6de18>]
>>tree2: [<xmlNode (end) object at 0x6d878>, <xmlNode (alpha) object at 
>>0x6df08>]
>>
>>(I've snipped the ends of the lists for clarity.)
>>
>>Now, I know that the <xmlNode (alpha) object> in each list are 
>>references to the same node: There's only one <alpha> element in the 
>>entire document. However, if I do tree1[1] == tree2[1] it returns 
>>false, which is a problem.
> 
> 
>   right, the underlying C object are the same but new wrappers are build
> on the fly. The equality should be defined by testing the C objects pointers,
> I don't know how to do this, 

If you implement the wrappers in Python and have access to the
underlying C object pointers, you can implement this by overriding:

def __cmp__(self, other):
     if isinstance(other, self.__class__):
         return cmp(self._cobject, other._cobject)
     else:
         raise TypeError

The same is possible at C level by providing the tp_compare
slot.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 29 2004)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2004-01-23: Released mxODBC.Zope.DA 1.0.8        http://zope.egenix.com/

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the XML-SIG mailing list