sudo gem install nokogiri

An HTML, XML, SAX, & Reader parser with the ability to search documents via XPath or CSS3 selectors… and much more


Class Nokogiri::XML::SAX::PushParser inherits from Object

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.


parser = {
def start_document
  puts "start document called"
parser << "<div>hello<"
parser << "/div>"


document RW

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

Public Class Methods

new(doc =, file_name = nil, encoding = 'UTF-8') Show 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 =, file_name = nil, encoding = 'UTF-8') @document = doc @encoding = encoding @sax_parser = ## Create our push parser context initialize_native(@sax_parser, file_name) end

Public Instance Methods

<<(chunk, last_chunk = false)
finish() Show 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() Show Source
static VALUE get_options(VALUE self) { xmlParserCtxtPtr ctx; Data_Get_Struct(self, xmlParserCtxt, ctx); return INT2NUM(ctx->options); }
options=(p1) Show Source
static VALUE set_options(VALUE self, VALUE options) { xmlParserCtxtPtr ctx; Data_Get_Struct(self, xmlParserCtxt, ctx); if (xmlCtxtUseOptions(ctx, (int)NUM2INT(options)) != 0) rb_raise(rb_eRuntimeError, "Cannot set XML parser context options"); return Qnil; }
write(chunk, last_chunk = false) Show 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