Class: Nokogiri::XML::SAX::Document

Class | Nokogiri::XML::SAX::Document
In: | lib/nokogiri/xml/sax/document.rb
Parent: | Object

This class is used for registering types of events you are interested in handling. All of the methods on this class are available as possible events while parsing an XML document. To register for any particular event, just subclass this class and implement the methods you are interested in knowing about.

To only be notified about start and end element events, write a class like this:

      class MyDocument < Nokogiri::XML::SAX::Document
        def start_element name, attrs = []
          puts "#{name} started!"
        end

        def end_element name
          puts "#{name} ended"
        end
      end

You can use this event handler for any SAX style parser included with Nokogiri. See Nokogiri::XML::SAX, and Nokogiri::HTML::SAX.

### Methods

cdata_block characters comment end_document end_element end_element_namespace error start_document start_element start_element_namespace warning

### Public Instance methods

cdata_block(string)

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

characters(string)

Characters read between a tag `string` contains the character data

comment(string)

Called when comments are encountered `string` contains the comment data

end_document()

Called when document ends parsing

end_element(name)

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

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

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(string)

Called on document errors `string` contains the error

start_document()

Called when document starts parsing

start_element(name, attrs = [])

Called at the beginning of an element `name` is the name of the tag with `attrs` as attributes

start_element_namespace(name, attrs = {})

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(string)

Called on document warnings `string` contains the warning

[Validate]