123456789_123456789_123456789_123456789_123456789_

Class: Nokogiri::HTML4::SAX::Parser

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Nokogiri::XML::SAX::Parser
Defined in: lib/nokogiri/html4/sax/parser.rb,
ext/nokogiri/html4_sax_parser.c

Overview

This parser is a ::Nokogiri::HTML4::SAX style parser that reads its input as it deems necessary. The parser takes a ::Nokogiri::XML::SAX::Document, an optional encoding, then given an ::Nokogiri::HTML input, sends messages to the ::Nokogiri::XML::SAX::Document.

⚠ This is an ::Nokogiri::HTML4 parser and so may not support some ::Nokogiri::HTML5 features and behaviors.

Here is a basic usage example:

class MyHandler < Nokogiri::XML::SAX::Document
  def start_element name, attributes = []
    puts "found a #{name}"
  end
end

parser = Nokogiri::HTML4::SAX::Parser.new(MyHandler.new)

# Hand an IO object to the parser, which will read the HTML from the IO.
File.open(path_to_html) do |f|
  parser.parse(f)
end

For more information on SAX parsers, see ::Nokogiri::XML::SAX or the parent class ::Nokogiri::XML::SAX::Parser.

Also see ::Nokogiri::XML::SAX::Document for the available events.

Constant Summary

::Nokogiri::ClassResolver - Included

VALID_NAMESPACES

::Nokogiri::XML::SAX::Parser - Inherited

ENCODINGS, REVERSE_ENCODINGS

Class Method Summary

::Nokogiri::XML::SAX::Parser - Inherited

.new

Create a new Parser.

Instance Attribute Summary

::Nokogiri::XML::SAX::Parser - Inherited

#document

The ::Nokogiri::XML::SAX::Document where events will be sent.

#encoding

The encoding beings used for this document.

Instance Method Summary

::Nokogiri::XML::SAX::Parser - Inherited

#parse

Parse the input, sending events to the SAX::Document at #document.

#parse_file

Parse a file.

#parse_io

Parse an input stream.

#parse_memory

Parse an input string.

#initialize_native

::Nokogiri::ClassResolver - Included

#related_class

Find a class constant within the.

Constructor Details

This class inherits a constructor from Nokogiri::XML::SAX::Parser

Instance Method Details

#initialize_native (private)

[ GitHub ]

  
# File 'ext/nokogiri/html4_sax_parser.c', line 19

static VALUE
noko_html4_sax_parser_initialize(VALUE self)
{
  xmlSAXHandlerPtr handler = noko_xml_sax_parser_unwrap(self);

  rb_call_super(0, NULL);

  handler->startDocument = noko_html4_sax_parser_start_document;

  return self;
}