Install
sudo gem install nokogiri
Contribute
github.com/tenderlove/nokogiri

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

Nokogiri

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.

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') 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 34: def initialize(doc = XML::SAX::Document.new, file_name = nil, encoding = 'UTF-8') 35: @document = doc 36: @encoding = encoding 37: @sax_parser = XML::SAX::Parser.new(doc) 38: 39: ## Create our push parser context 40: initialize_native(@sax_parser, file_name) 41: 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 54: def finish 55: write '', true 56: end
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 46: def write chunk, last_chunk = false 47: native_write(chunk, last_chunk) 48: end