You can also read the file line by line, and use a hash of replacements 
with gsub:

replacements = {
  '{username}' => 'BOB',
  '{password}' => 'BOB-PASSWORD',
  '{userroot}' => 'BOB-USERROOT'
}

pattern = '{.*?}'

File.open('out.xml') do |outfile|
  IO.foreach('in.xml') do |line|
    outfile.print gsub(/#{pattern}/, replacements)
  end
end

-- 
Posted via http://www.ruby-forum.com/.