I've written some simple routines to walk an XML ontology with xml/ 
libxml, and noticed that putting XML::Node objects into lists and  
returning them may lead to a situation where two lists contain the  
same node with different object_id's.  Here's an exmple, funstion  
ancestors:

require 'xml/libxml'

# extend XML::Node with helper methods
class XML::Node
   def ancestors(node_type=nil)
     #print "=>"
     res = []
     p = self
     while p = p.parent and p.name do
       next if node_type and p.name != node_type
       res << p if p
       #puts "added #{p.name}"
     end
     res.reverse
   end

   # ... -- more methods
end

Now I found that if I call it on some tree and get at least two  
nodes, and then compare the first elements of each list, which should  
be the root in both cases, I get different object_id's.  But ==  
returns equality.  What's going on here?  Hpricot used to maintain  
the same object_id across assignments, which is usually the case in  
Ruby...  Are there any think objects created for XML::Node's here?

Cheers,
Alexy 
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to