From: Robert Klemme Date: 2010-01-27T17:50:23+09:00 Subject: Re: Build an array using data from an exisiting array 2010/1/27 Sean Warburton : > burke wrote: >> How about something like: >> >> file_names = ["a.xml", "b.xml", "c.xml", "d.xml", "e.xml"] >> file_contentses = file_names.map{|file| File.read(file)} >> >> >> so now you can do `file_contentses[0]`, for example, to get the >> contents of a.xml. > > Hello Burke, thanks for the reply, I used the word file but I don't > actually build a file, sorry. What i should have said is that I want to > build an array of five XML requests , populating each request with the > data from an existing array of five items that will be passed as an > argument. Does that sound clearer and make more sense? Are you looking for something like this? irb(main):011:0> require 'rexml/document' => true irb(main):012:0> docs = (1..5).map do |i| irb(main):013:1* d = REXML::Document.new irb(main):014:1> d.add_element("my_root").text = "item no. #{i}" irb(main):015:1> d.to_s irb(main):016:1> end => ["item no. 1", "item no. 2", "item no. 3", "item no. 4", "item no. 5"] irb(main):017:0> docs[2] => "item no. 3" irb(main):018:0> Of course your document construction is likely more complex. see http://www.germane-software.com/software/rexml/ Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/