[libxml-devel] Changing node equality
Sean Chittenden
sean at chittenden.org
Tue Jul 8 14:49:47 EDT 2008
>>>> Hmmm... How does the C library itself handle comparison?
>>> Well, in C the == is identity (comparing pointer addresses). libxml
>>> does not provide an equality method that I see.
>> So there is no way to compare on content, only identity.
>
> Well, its easy enough:
>
> if node1.to_s == node2.to_s
>
> Or
>
> if node1.content == node2.content
>
> to_s is like outerHTML and content is innerHTML (sort of).
Actually, how about this (pseudo):
def ==(arg)
if arg.kind_of? XML::Node
return true if self.id == arg.id
else
return true if self.to_s == arg
end
end
That way you don't have to create and throw away an object needlessly
in most comparison cases. -sc
--
Sean Chittenden
sean at chittenden.org
More information about the libxml-devel
mailing list