Created
October 1, 2010 21:51
-
-
Save rickhull/606922 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ResponseSAX < Nokogiri::XML::SAX::Document | |
| attr_reader :fields | |
| def start_document | |
| puts "Starting the parse" | |
| @fields = {} | |
| @char_buf = '' | |
| @start_fields = false | |
| end | |
| def start_element(name, attrs = []) | |
| @start_fields = true if name.downcase == 'fields' | |
| end | |
| def characters(str) | |
| @char_buf << str if @start_fields | |
| end | |
| def end_element(name) | |
| @start_fields = false if name.downcase == 'fields' | |
| if @start_fields and !@char_buf.empty? | |
| puts "Set #{name.downcase} to #{@char_buf[0..5]}..." | |
| @fields[name.downcase.to_sym] = @char_buf | |
| @char_buf = '' | |
| end | |
| end | |
| def end_document | |
| puts "Done parsing!" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment