# File lib/html5/html5parser.rb, line 61
    def _parse(stream, inner_html, encoding, container = 'div')
      @tree.reset
      @first_start_tag = false
      @errors = []

      @tokenizer = @tokenizer.class unless Class === @tokenizer
      @tokenizer = @tokenizer.new(stream, :encoding => encoding,
        :parseMeta => !inner_html, :lowercase_attr_name => @lowercase_attr_name, :lowercase_element_name => @lowercase_element_name)

      if inner_html
        case @inner_html = container.downcase
        when 'title', 'textarea'
          @tokenizer.content_model_flag = :RCDATA
        when 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes', 'noscript'
          @tokenizer.content_model_flag = :CDATA
        when 'plaintext'
          @tokenizer.content_model_flag = :PLAINTEXT
        else
          # content_model_flag already is PCDATA
          @tokenizer.content_model_flag = :PCDATA
        end
      
        @phase = @phases[:rootElement]
        @phase.insert_html_element
        reset_insertion_mode
      else
        @inner_html = false
        @phase = @phases[:initial]
      end

      # We only seem to have InBodyPhase testcases where the following is
      # relevant ... need others too
      @last_phase = nil

      # XXX This is temporary for the moment so there isn't any other
      # changes needed for the parser to work with the iterable tokenizer
      @tokenizer.each do |token|
        token = normalize_token(token)

        method = 'process%s' % token[:type]

        case token[:type]
        when :Characters, :SpaceCharacters, :Comment
          @phase.send method, token[:data]
        when :StartTag
          @phase.send method, token[:name], token[:data]
        when :EndTag
          @phase.send method, token[:name]
        when :Doctype
          @phase.send method, token[:name], token[:publicId],
            token[:systemId], token[:correct]
        else
          parse_error(token[:data], token[:datavars])
        end
      end

      # When the loop finishes it's EOF
      @phase.process_eof
    end