class Nokogiri::XML::SAX::Document

Nokogiri::XML::SAX, and Nokogiri::HTML4::SAX.
You can use this event handler for any SAX style parser included with Nokogiri. See
end
end
puts “#{name} ended”
def end_element name
end
puts “#{name} started!”
def start_element name, attrs = []
class MyDocument < Nokogiri::XML::SAX::Document
To only be notified about start and end element events, write a class like this:
are interested in knowing about.
register for any particular event, just subclass this class and implement the methods you
the methods on this class are available as possible events while parsing an XML document. To
This class is used for registering types of events you are interested in handling. All of
##

def cdata_block(string)

+string+ contains the cdata content
Called when cdata blocks are found
##
def cdata_block(string)
end

def characters(string)

+string+ contains the character data

times given one contiguous string of characters.
Characters read between a tag. This method might be called multiple
##
def characters(string)
end

def comment(string)

+string+ contains the comment data
Called when comments are encountered
##
def comment(string)
end

def end_document

Called when document ends parsing
##
def end_document
end

def end_element(name)

+name+ is the tag name
Called at the end of an element
##
def end_element(name)
end

def end_element_namespace(name, prefix = nil, uri = nil)

+uri+ is the associated namespace URI
+prefix+ is the namespace prefix associated with the element
+name+ is the element's name
Called at the end of an element
##
def end_element_namespace(name, prefix = nil, uri = nil)
  ###
  # Deal with SAX v1 interface
  end_element([prefix, name].compact.join(":"))
end

def error(string)

+string+ contains the error
Called on document errors
##
def error(string)
end

def processing_instruction(name, content)

+content+ is the value of the instruction
+name+ is the target of the instruction
Called when processing instructions are found
##
def processing_instruction(name, content)
end

def start_document

Called when document starts parsing
##
def start_document
end

def start_element(name, attrs = [])

[ ["xmlns:foo", "http://sample.net"], ["size", "large"] ]
* +attrs+ are an assoc list of namespaces and attributes, e.g.:
* +name+ is the name of the tag
Called at the beginning of an element
##
def start_element(name, attrs = [])
end

def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) # rubocop:disable Metrics/ParameterLists

rubocop:disable Metrics/ParameterLists
+ns+ is a hash of namespace prefix:urls associated with the element
+uri+ is the associated namespace URI
+prefix+ is the namespace prefix for the element
+attrs+ is a list of attributes
+name+ is the element name
Called at the beginning of an element
##
def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) # rubocop:disable Metrics/ParameterLists
  ###
  # Deal with SAX v1 interface
  name = [prefix, name].compact.join(":")
  attributes = ns.map do |ns_prefix, ns_uri|
    [["xmlns", ns_prefix].compact.join(":"), ns_uri]
  end + attrs.map do |attr|
    [[attr.prefix, attr.localname].compact.join(":"), attr.value]
  end
  start_element(name, attributes)
end

def warning(string)

+string+ contains the warning
Called on document warnings
##
def warning(string)
end

def xmldecl(version, encoding, standalone)

Called when an XML declaration is parsed
##
def xmldecl(version, encoding, standalone)
end