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
Called when cdata blocks are found
##
def cdata_block string end
def characters string
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
Called when comments are encountered
##
def comment string end
def end_document
##
def end_document end
def end_element name
Called at the end of an element
##
def end_element name end
def end_element_namespace name, prefix = nil, uri = nil
+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
Called on document errors
##
def error string end
def processing_instruction name, content
+name+ is the target of the instruction
Called when processing instructions are found
##
def processing_instruction name, content end
def start_document
##
def start_document end
def start_element name, attrs = []
* +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 = []
+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
Called on document warnings
##
def warning string end
def xmldecl version, encoding, standalone
##
def xmldecl version, encoding, standalone end