class Nokogiri::XML::SAX::PushParser

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.

#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

Attributes

document[RW]

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

Public Class Methods

new(doc = XML::SAX::Document.new, file_name = nil, encoding = 'UTF-8') click to toggle source

Create a new PushParser with doc as the SAX Document, providing an optional file_name and encoding

# File lib/nokogiri/xml/sax/push_parser.rb, line 34
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

Public Instance Methods

<<(chunk, last_chunk = false) click to toggle source
Alias for: write
finish() click to toggle source

Finish the parsing. This method is only necessary for Nokogiri::XML::SAX::Document#end_document to be called.

# File lib/nokogiri/xml/sax/push_parser.rb, line 54
def finish
  write '', true
end
options() click to toggle source
# File lib/nokogiri/ffi/xml/sax/push_parser.rb, line 8
def options
  cstruct[:options]
end
options=(user_options) click to toggle source
# File lib/nokogiri/ffi/xml/sax/push_parser.rb, line 12
def options=(user_options)
  if LibXML.xmlCtxtUseOptions(cstruct, user_options) != 0
    raise RuntimeError, "Cannot set XML parser context options"
  end
  nil
end
write(chunk, last_chunk = false) click to toggle source

Write a chunk of XML to the PushParser. Any callback methods that can be called will be called immediately.

# File lib/nokogiri/xml/sax/push_parser.rb, line 46
def write chunk, last_chunk = false
  native_write(chunk, last_chunk)
end
Also aliased as: <<