Sha256: a92090d8ae59f6c6d15bf0f36405a8aed4525d889ca9761525e971077008c65b

Contents?: true

Size: 1.85 KB

Versions: 163

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true
module Nokogiri
  module XML
    module SAX
      ###
      # PushParser can parse a document that is fed to it manually.  It
      # must be given a SAX::Document object which will be called with
      # SAX events as the document is being parsed.
      #
      # Calling PushParser#<< writes XML to the parser, calling any SAX
      # callbacks it can.
      #
      # PushParser#finish tells the parser that the document is finished
      # and calls the end_document SAX method.
      #
      # Example:
      #
      #   parser = PushParser.new(Class.new(XML::SAX::Document) {
      #     def start_document
      #       puts "start document called"
      #     end
      #   }.new)
      #   parser << "<div>hello<"
      #   parser << "/div>"
      #   parser.finish
      class PushParser

        # The Nokogiri::XML::SAX::Document on which the PushParser will be
        # operating
        attr_accessor :document

        ###
        # Create a new PushParser with +doc+ as the SAX Document, providing
        # an optional +file_name+ and +encoding+
        def initialize(doc = XML::SAX::Document.new, file_name = nil, encoding = 'UTF-8')
          @document = doc
          @encoding = encoding
          @sax_parser = XML::SAX::Parser.new(doc)

          ## Create our push parser context
          initialize_native(@sax_parser, file_name)
        end

        ###
        # Write a +chunk+ of XML to the PushParser.  Any callback methods
        # that can be called will be called immediately.
        def write chunk, last_chunk = false
          native_write(chunk, last_chunk)
        end
        alias :<< :write

        ###
        # Finish the parsing.  This method is only necessary for
        # Nokogiri::XML::SAX::Document#end_document to be called.
        def finish
          write '', true
        end
      end
    end
  end
end

Version data entries

163 entries across 156 versions & 6 rubygems

Version Path
nokogiri-backport-1.11.0 lib/nokogiri/xml/sax/push_parser.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.11.6-x86_64-linux/lib/nokogiri/xml/sax/push_parser.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/xml/sax/push_parser.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/xml/sax/push_parser.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5 lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5-x86_64-linux lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5-x86_64-darwin lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5-x86-mingw32 lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5-x86-linux lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5-x64-mingw32 lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5-java lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.5-arm64-darwin lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.4 lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.4-x86_64-linux lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.4-x86_64-darwin lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.4-x86-mingw32 lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.4-x86-linux lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.4-x64-mingw32 lib/nokogiri/xml/sax/push_parser.rb
nokogiri-1.12.4-java lib/nokogiri/xml/sax/push_parser.rb