class Nokogiri::XML::SAX::Document

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

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 = []

+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 = []
  ###
  # Deal with SAX v1 interface
  name = [prefix, name].compact.join(':')
  attributes = ns.map { |ns_prefix,ns_uri|
    [['xmlns', ns_prefix].compact.join(':'), ns_uri]
  } + attrs.map { |attr|
    [[attr.prefix, attr.localname].compact.join(':'), attr.value]
  }
  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