class Nokogiri::HTML4::SAX::Parser

For more information on SAX parsers, see Nokogiri::XML::SAX<br><br>parser.parse(File.read(ARGV, mode: ‘rb’))
parser = Nokogiri::HTML4::SAX::Parser.new(MyDoc.new)
end
end
puts “found a #{name}”
def start_element name, attributes = []
class MyDoc < Nokogiri::XML::SAX::Document
Here is a basic usage example:
This class lets you perform SAX style parsing on HTML with HTML error correction.
##

def parse_file(filename, encoding = "UTF-8")

Parse a file with +filename+
##
def parse_file(filename, encoding = "UTF-8")
  raise ArgumentError unless filename
  raise Errno::ENOENT unless File.exist?(filename)
  raise Errno::EISDIR if File.directory?(filename)
  ctx = ParserContext.file(filename, encoding)
  yield ctx if block_given?
  ctx.parse_with(self)
end

def parse_io(io, encoding = "UTF-8")

Parse given +io+
##
def parse_io(io, encoding = "UTF-8")
  check_encoding(encoding)
  @encoding = encoding
  ctx = ParserContext.io(io, ENCODINGS[encoding])
  yield ctx if block_given?
  ctx.parse_with(self)
end

def parse_memory(data, encoding = "UTF-8")

Parse html stored in +data+ using +encoding+
##
def parse_memory(data, encoding = "UTF-8")
  raise TypeError unless String === data
  return if data.empty?
  ctx = ParserContext.memory(data, encoding)
  yield ctx if block_given?
  ctx.parse_with(self)
end