summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-22 06:14:49 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-22 06:14:49 +0000
commitc83264c3f9a6b7b01685229f912003c7d644f69d (patch)
tree475247abab1b7c4b8dc96f28860e2cd118dad420 /sample
parentaeac7335eae3478a1e0a2ca2aaa24ee5de4b6715 (diff)
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rwxr-xr-xsample/rss/re_read.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/sample/rss/re_read.rb b/sample/rss/re_read.rb
new file mode 100755
index 0000000..c19a509
--- /dev/null
+++ b/sample/rss/re_read.rb
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby
+
+require "rss"
+
+def error(exception)
+ mark = "=" * 20
+ mark = "#{mark} error #{mark}"
+ puts mark
+ puts exception.class
+ puts exception.message
+ puts exception.backtrace
+ puts mark
+end
+
+verbose = false
+before_time = Time.now
+
+ARGV.each do |fname|
+ if fname == '-v'
+ verbose = true
+ next
+ end
+ source = nil
+ File.open(fname) do |f|
+ source = f.read
+ end
+
+ rss = nil
+ read = false
+ begin
+ rss = RSS::Parser.parse(source)
+ puts "Re-read valid RSS: #{fname}"
+ RSS::Parser.parse(rss.to_s)
+ read = true
+ rescue RSS::InvalidRSSError
+ error($!) if verbose
+ ## do non validate parse for invalid RSS 1.0
+ begin
+ rss = RSS::Parser.parse(source, false)
+ rescue RSS::Error
+ ## invalid RSS.
+ error($!) if verbose
+ end
+ rescue RSS::Error
+ error($!) if verbose
+ end
+
+ if rss.nil?
+ puts "Invalid RSS: #{fname}"
+ elsif !read
+ puts "Re-read invalid RSS: #{fname}"
+ begin
+ RSS::Parser.parse(rss.to_s)
+ rescue RSS::Error
+ puts " Error occurred: #{fname}"
+ error($!) if verbose
+ end
+ end
+end
+
+processing_time = Time.now - before_time
+
+puts "Used XML parser: #{RSS::Parser.default_parser}"
+puts "Processing time: #{processing_time}s"