nokogiri-ext
Description
nokogiri-ext is a collection of useful extensions to the nokogiri gem.
Features
- Adds an
==
method to {Nokogiri::XML::Element}, {Nokogiri::XML::Attr}, {Nokogiri::XML::Text}, {Nokogiri::XML::Node}. - Adds a
traverse_count
method to {Nokogiri::XML::Document} and {Nokogiri::XML::Node}. - Adds the {Nokogiri::XML::Node#traverse_text} method.
Requirements
Install
$ gem install nokogiri-ext
gemspec
gem.add_dependency 'nokogiri-ext', '~> 1.0'
Gemfile
gem 'nokogiri-ext', '~> 1.0'
Examples
equality
Compare the contents of two XML/HTML elements:
require 'nokogiri/ext/equality'
doc1.at('//node') == doc2.at('//node')
Comparing the contents of two XML/HTML documents:
doc1 == doc2
traverse_count
Count the total number of elements under a XML/HTML element:
require 'nokogiri/ext/traverse_count'
doc.at('//node').traverse_count
# => 7
Count the total number of elements within a XML/HTML document:
doc.traverse_count
# => 42
traverse_text
Traverses all text nodes in a XML/HTML document or node:
require 'nokogiri/ext/traverse_text'
doc.traverse_text do |text|
puts text
end
License
See {file:LICENSE.txt} for details.