From: Robert Klemme Date: 2012-04-26T20:33:22+09:00 Subject: Re: if if if statment On Thu, Apr 26, 2012 at 12:49 PM, Lars Haugseth wrote: > On 04/26/2012 11:23 AM, fox foxmaster wrote: >> >> Lars I thought I check out nokogiri ^^ and humm I feel completely lost, >> I am trying to find examples on how to use it in the way that I want, I >> really don't get the examples on the nokogiri web page, >> >> So Lars or anyone else, would you like to show me howto use it in the >> code I have? Just two nitpicks with regard to file handling: > First, you need to parse the source XML into a DOM object: > >  require 'nokogiri' > >  dom = Nokogiri::XML(File.read source_file) # make Nokogiri read from the file to avoid to copy the whole file into memory # and read binary! dom = File.open(source_file, 'rb') {|io| Nokogiri.XML(io)} > Then you iterate over all InterfaceGroup nodes and modify attributes: > >  dom.xpath("//InterfaceGroup").each do |node| >    node['Members'] = "some value" >  end > > Finally, write the modified DOM to the target XML file: > >  File.open(target_file, "w") { |f| f.write dom.to_xml } # again avoid the copy and write binary File.open(target_file, 'wb') { |io| dom.write_to io } Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/