123456789_123456789_123456789_123456789_123456789_

Class: Nokogiri::HTML4::EncodingReader::SAXHandler

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Nokogiri::XML::SAX::Document
Defined in: lib/nokogiri/html4/encoding_reader.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::Nokogiri::XML::SAX::Document - Inherited

#cdata_block

Called when cdata blocks are found string contains the cdata content.

#characters

Characters read between a tag.

#comment

Called when comments are encountered string contains the comment data.

#end_document

Called when document ends parsing.

#end_element

Called at the end of an element name is the tag name.

#end_element_namespace

Called at the end of an element name is the element’s name prefix is the namespace prefix associated with the element uri is the associated namespace URI.

#error

Called on document errors string contains the error.

#processing_instruction

Called when processing instructions are found name is the target of the instruction content is the value of the instruction.

#start_document

Called when document starts parsing.

#start_element

Called at the beginning of an element * name is the name of the tag * attrs are an assoc list of namespaces and attributes, e.g.:

#start_element_namespace

Called at the beginning of an element name is the element name attrs is a list of attributes prefix is the namespace prefix for the element uri is the associated namespace URI ns is a hash of namespace prefix:urls associated with the element.

#warning

Called on document warnings string contains the warning.

#xmldecl

Called when an ::Nokogiri::XML declaration is parsed.

Constructor Details

.newSAXHandler

[ GitHub ]

  
# File 'lib/nokogiri/html4/encoding_reader.rb', line 27

def initialize
  @encoding = nil
  super()
end

Instance Attribute Details

#encoding (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/html4/encoding_reader.rb', line 25

attr_reader :encoding

Instance Method Details

#start_element(name, attrs = [])

[ GitHub ]

  
# File 'lib/nokogiri/html4/encoding_reader.rb', line 32

def start_element(name, attrs = [])
  return unless name == "meta"

  attr = Hash[attrs]
  (charset = attr["charset"]) &&
    (@encoding = charset)
  (http_equiv = attr["http-equiv"]) &&
    http_equiv.match(/\AContent-Type\z/i) &&
    (content = attr["content"]) &&
    (m = content.match(/;\s*charset\s*=\s*([\w-]+)/)) &&
    (@encoding = m[1])
end