From: Robert Klemme Date: 2011-04-14T23:40:16+09:00 Subject: Re: removing nodes from Nokogiri::XML::NodeSet On Thu, Apr 14, 2011 at 3:31 PM, Ted Flethuseo wrote: > It doesn't remove it though. I also don't want specifically to remove > the first or last node, often I want to remove one somewhere in the > middle of the array. > > puts nodes.length > nodes[0].remove > puts nodes.length > > when I run that code I have originally 4 nodes, and after, I still have > 4 nodes. I found a way to do this but I disklike it, because it has to > search for the node every time it needs to erase it. > > puts nodes.length > nodes.delete(nodes[0]) > puts nodes.length You want method #remove: irb(main):006:0> doc = Nokogiri::XML("12") => #]>, #]>]>]> irb(main):007:0> puts doc 1 2 => nil irb(main):008:0> doc.xpath('//test') => [#]>, #]>] irb(main):009:0> doc.xpath('//test[last()]') => [#]>] irb(main):010:0> doc.xpath('//test[last()]').remove => [#]>] irb(main):011:0> puts doc 1 => nil Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/