Permalink
Browse files

Merge pull request #78 from monde/master

Example of actively yielding results from the SAX parser.
  • Loading branch information...
2 parents 21fa3c8 + a276f02 commit a491425730b07209d28decf1d8a9e6f304961570 @ohler55 committed Sep 11, 2013
Showing with 32 additions and 0 deletions.
  1. +32 −0 README.md
View
@@ -171,6 +171,38 @@ Ox.sax_parse(handler, io)
# end: top
```
+### Yielding results immediately while SAX XML Parsing:
+
+```ruby
+require 'stringio'
+require 'ox'
+
+class Yielder < ::Ox::Sax
+ def initialize(block); @yield_to = block; end
+ def start_element(name); @yield_to.call(name); end
+end
+
+io = StringIO.new(%{
+<top name="sample">
+ <middle name="second">
+ <bottom name="third"/>
+ </middle>
+</top>
+})
+
+proc = Proc.new { |name| puts name }
+handler = Yielder.new(proc)
+puts "before parse"
+Ox.sax_parse(handler, io)
+puts "after parse"
+# outputs
+# before parse
+# top
+# middle
+# bottom
+# after parse
+```
+
### Object XML format
The XML format used for Object encoding follows the structure of the

0 comments on commit a491425

Please sign in to comment.