Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add simple example.

  • Loading branch information...
commit c899b0b291365e2fd7008336f11a8ffa6f5d46fa 1 parent 09b0c65
@headius authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 examples/basic.rb
View
37 examples/basic.rb
@@ -0,0 +1,37 @@
+require 'rx'
+require 'rx/rexml'
+
+# A basic example of REXML listener parsing using RX
+class Listener
+ def doctype(name, pub_sys, long_name, uri)
+ puts "doctype: #{name}"
+ end
+
+ def cdata(x)
+ puts "CDATA: #{x}"
+ end
+ def comment(x)
+ puts "comment: #{x}"
+ end
+
+ def instruction(name, instruction)
+ puts "instruction: #{name} #{instruction}"
+ end
+
+ def tag_start(name, attrs)
+ puts "tag start: #{name} #{attrs}"
+ end
+
+ def tag_end(name)
+ puts "tag end: #{name}"
+ end
+
+ def text(text)
+ puts "text: #{text}"
+ end
+end
+
+File.open(ARGV[0] || fail('specify file')) do |file|
+ reader = RX::Reader.new(file, RX::RXToStreamListener.new(Listener.new))
+ reader.go
+end
Please sign in to comment.
Something went wrong with that request. Please try again.