Skip to content

Instantly share code, notes, and snippets.

@rickhull
Created October 1, 2010 21:51
Show Gist options
  • Select an option

  • Save rickhull/606922 to your computer and use it in GitHub Desktop.

Select an option

Save rickhull/606922 to your computer and use it in GitHub Desktop.
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