/tools/Ruby/lib/ruby/1.8/rexml/parsers/streamparser.rb

http://github.com/agross/netopenspace · Ruby · 46 lines · 42 code · 2 blank · 2 comment · 2 complexity · a05611742797b26b29afc6add088c1ca MD5 · raw file

  1. module REXML
  2. module Parsers
  3. class StreamParser
  4. def initialize source, listener
  5. @listener = listener
  6. @parser = BaseParser.new( source )
  7. end
  8. def add_listener( listener )
  9. @parser.add_listener( listener )
  10. end
  11. def parse
  12. # entity string
  13. while true
  14. event = @parser.pull
  15. case event[0]
  16. when :end_document
  17. return
  18. when :start_element
  19. attrs = event[2].each do |n, v|
  20. event[2][n] = @parser.unnormalize( v )
  21. end
  22. @listener.tag_start( event[1], attrs )
  23. when :end_element
  24. @listener.tag_end( event[1] )
  25. when :text
  26. normalized = @parser.unnormalize( event[1] )
  27. @listener.text( normalized )
  28. when :processing_instruction
  29. @listener.instruction( *event[1,2] )
  30. when :start_doctype
  31. @listener.doctype( *event[1..-1] )
  32. when :end_doctype
  33. # FIXME: remove this condition for milestone:3.2
  34. @listener.doctype_end if @listener.respond_to? :doctype_end
  35. when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
  36. @listener.send( event[0].to_s, *event[1..-1] )
  37. when :entitydecl, :notationdecl
  38. @listener.send( event[0].to_s, event[1..-1] )
  39. end
  40. end
  41. end
  42. end
  43. end
  44. end