Install
sudo gem install nokogiri
Contribute
github.com/tenderlove/nokogiri

An HTML, XML, SAX, & Reader parser with the ability to search documents via XPath or CSS3 selectors… and much more

Nokogiri

Class Nokogiri::XML::SAX::Document inherits from 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.

Public Instance Methods

cdata_block(string) Show Source
 

Called when cdata blocks are found string contains the cdata content

# File lib/nokogiri/xml/sax/document.rb, line 157 157: def cdata_block string 158: end
characters(string) Show Source
 

Characters read between a tag. This method might be called multiple times given one contiguous string of characters.

string contains the character data

# File lib/nokogiri/xml/sax/document.rb, line 133 133: def characters string 134: end
comment(string) Show Source
 

Called when comments are encountered string contains the comment data

# File lib/nokogiri/xml/sax/document.rb, line 139 139: def comment string 140: end
end_document() Show Source
 

Called when document ends parsing

# File lib/nokogiri/xml/sax/document.rb, line 83 83: def end_document 84: end
end_element(name) Show Source
 

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

# File lib/nokogiri/xml/sax/document.rb, line 95 95: def end_element name 96: end
end_element_namespace(name, prefix = nil, uri = nil) Show Source
 

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

# File lib/nokogiri/xml/sax/document.rb, line 122 122: def end_element_namespace name, prefix = nil, uri = nil 123: ### 124: # Deal with SAX v1 interface 125: end_element [prefix, name].compact.join(':') 126: end
error(string) Show Source
 

Called on document errors string contains the error

# File lib/nokogiri/xml/sax/document.rb, line 151 151: def error string 152: end
start_document() Show Source
 

Called when document starts parsing

# File lib/nokogiri/xml/sax/document.rb, line 78 78: def start_document 79: end
start_element(name, attrs = []) Show Source
 

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

# File lib/nokogiri/xml/sax/document.rb, line 89 89: def start_element name, attrs = [] 90: end
start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) Show Source
 

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

# File lib/nokogiri/xml/sax/document.rb, line 105 105: def start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = [] 106: ### 107: # Deal with SAX v1 interface 108: name = [prefix, name].compact.join(':') 109: attributes = ns.map { |ns_prefix,ns_uri| 110: [['xmlns', ns_prefix].compact.join(':'), ns_uri] 111: } + attrs.map { |attr| 112: [[attr.prefix, attr.localname].compact.join(':'), attr.value] 113: }.flatten 114: start_element name, attributes 115: end
warning(string) Show Source
 

Called on document warnings string contains the warning

# File lib/nokogiri/xml/sax/document.rb, line 145 145: def warning string 146: end
xmldecl(version, encoding, standalone) Show Source
 

Called when an XML declaration is parsed

# File lib/nokogiri/xml/sax/document.rb, line 73 73: def xmldecl version, encoding, standalone 74: end