Class: REXML::Parsers::StreamParser (Ruby 2.4.2)
Description: Class : REXML::Parsers::StreamParser - Ruby 2.4.2

Support for the Ruby 2.4 series has ended. See here for reference.

### Home Classes Methods

### In Files

- rexml/parsers/streamparser.rb

### Parent

Object

### Methods

- ::new
- #add_listener
- #parse

### Class/Module Index

Quicksearch

- Array
- Float
- Integer
- Object
- REXML
- REXML::AttlistDecl
- REXML::Attribute
- REXML::Attributes
- REXML::CData
- REXML::Child
- REXML::Comment
- REXML::DTD
- REXML::DTD::AttlistDecl
- REXML::DTD::ElementDecl
- REXML::DTD::EntityDecl
- REXML::DTD::NotationDecl
- REXML::DTD::Parser
- REXML::Declaration
- REXML::DocType
- REXML::Document
- REXML::Element
- REXML::ElementDecl
- REXML::Elements
- REXML::Encoding
- REXML::Entity
- REXML::EntityConst
- REXML::ExternalEntity
- REXML::Formatters
- REXML::Formatters::Default
- REXML::Formatters::Pretty
- REXML::Formatters::Transitive
- REXML::Functions
- REXML::IOSource
- REXML::Instruction
- REXML::Light
- REXML::Light::Node
- REXML::Namespace
- REXML::Node
- REXML::NotationDecl
- REXML::Output
- REXML::Parent
- REXML::ParseException
- REXML::Parsers
- REXML::Parsers::BaseParser
- REXML::Parsers::LightParser
- REXML::Parsers::PullEvent
- REXML::Parsers::PullParser
- REXML::Parsers::SAX2Parser
- REXML::Parsers::StreamParser
- REXML::Parsers::TreeParser
- REXML::Parsers::UltraLightParser
- REXML::Parsers::XPathParser
- REXML::QuickPath
- REXML::SAX2Listener
- REXML::Security
- REXML::Source
- REXML::SourceFactory
- REXML::StreamListener
- REXML::SyncEnumerator
- REXML::Text
- REXML::UndefinedNamespaceException
- REXML::Validation
- REXML::Validation::Choice
- REXML::Validation::Event
- REXML::Validation::Interleave
- REXML::Validation::OneOrMore
- REXML::Validation::Optional
- REXML::Validation::Ref
- REXML::Validation::RelaxNG
- REXML::Validation::Sequence
- REXML::Validation::State
- REXML::Validation::ValidationException
- REXML::Validation::Validator
- REXML::Validation::ZeroOrMore
- REXML::XMLDecl
- REXML::XMLTokens
- REXML::XPath
- REXML::XPathParser
- Symbol

No matching classes.

# REXML::Parsers::StreamParser

### Public Class Methods

new(source, listener) click to toggle source

                   # File rexml/parsers/streamparser.rb, line 7
    def initialize source, listener
      @listener = listener
      @parser = BaseParser.new( source )
      @tag_stack = []
    end

### Public Instance Methods

add_listener( listener ) click to toggle source

                   # File rexml/parsers/streamparser.rb, line 13
    def add_listener( listener )
      @parser.add_listener( listener )
    end

parse() click to toggle source

                   # File rexml/parsers/streamparser.rb, line 17
    def parse
      # entity string
      while true
        event = @parser.pull
        case event[0]
        when :end_document
          unless @tag_stack.empty?
            tag_path = "/" + @tag_stack.join("/")
            raise ParseException.new("Missing end tag for '#{tag_path}'",
                                     @parser.source)
          end
          return
        when :start_element
          @tag_stack << event[1]
          attrs = event[2].each do |n, v|
            event[2][n] = @parser.unnormalize( v )
          end
          @listener.tag_start( event[1], attrs )
        when :end_element
          @listener.tag_end( event[1] )
          @tag_stack.pop
        when :text
          normalized = @parser.unnormalize( event[1] )
          @listener.text( normalized )
        when :processing_instruction
          @listener.instruction( *event[1,2] )
        when :start_doctype
          @listener.doctype( *event[1..-1] )
        when :end_doctype
          # FIXME: remove this condition for milestone:3.2
          @listener.doctype_end if @listener.respond_to? :doctype_end
        when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
          @listener.send( event[0].to_s, *event[1..-1] )
        when :entitydecl, :notationdecl
          @listener.send( event[0].to_s, event[1..-1] )
        when :externalentity
          entity_reference = event[1]
          content = entity_reference.gsub(/\A%|;\z/, "")
          @listener.entity(content)
        end
      end
    end