From: "Luca g. Soave" Date: 2007-01-26T19:29:35+09:00 Subject: Howto write SAX2Parser stream in to a file Hello, I'm new to Ruby and trying to write a stream in to a file, but I can just get an empty one. I tryed in different way found heare on the forum ( IO lib, Rio lib, out_file << "#{doc.parse}" and so on ). Here I show you the simplest : ----------------------------------------- require 'rexml/parsers/sax2parser' file = File.new "lapatyXML.xml" doc = REXML::Parsers::SAX2Parser.new file doc.listen(:characters, ["title"]) do |title| print "\"#{title}\" : " end doc.listen(:characters, ["link"]) do |link| print "#{link} : " end doc.listen(:characters, ["dc:date"]) do |date| print "#{date} : " end doc.listen(:characters, ["dc:subject"]) do |subject| puts "#{subject}" end File.open("outfile.xls","w") do |out_file| out_file.write "#{doc.parse}" end ------------------------------------------ Nothing seems to work, I just get an empty file "outfile.xls" . ... of course doc.parse contain a correct stream : irb(main):067:0> doc.inspect => "#], [:characters, \"link\", #], [:characters, \"dc:date\", #], [:characters, \"dc:subj ect\", #]], @tag_stack=[], @listeners=[], @has_listene rs=false, @namespace_stack=[], @parser=#, @er_source=#, @buffer=\"\", @line=0, @line_break=\">\", @orig=\"\", @to_utf=false, @encoding=\"UTF-8\">, @closed= nil, @stack=[], @tags=[], @entities=[]>, @entities={}>" irb(main):068:0> irb(main):018:0> doc.type (irb):18: warning: Object#type is deprecated; use Object#class => REXML::Parsers::SAX2Parser irb(main):019:0> doc.class => REXML::Parsers::SAX2Parser --------------------------------------------- Any suggestion ? Thanks in advance Lgs -- Posted via http://www.ruby-forum.com/.