From: transfire@...
Date: 2006-07-08T10:37:42+09:00
Subject: libhxml Node#remove! kills each loop and extension to #<<
hi,
While using #each to loop thru the children of a Node, if I remove a
node the loop breaks on it's own.
root.each { |node|
if XML::Node === node
node.content = "yep"
node.remove! if node['id'] = "b"
end
}
The result is
yep
Would tha tbe a bug? Or something that simply can't be avoided?
Also, I found this extension to #<< to be useful:
class XML::Node
alias_method :append, :<<
def <<( node )
if Array === node
node.each { |n| self.append n }
else
super
end
end
end
Thanks,
T.