Nokogiri parses and searches XML/HTML very quickly, and also has correctly implemented CSS3 selector support as well as XPath support.
Parsing a document returns either a Nokogiri::XML::Document, or a Nokogiri::HTML::Document depending on the kind of document you parse.
Here is an example:
require 'nokogiri' require 'open-uri' # Get a Nokogiri::HTML:Document for the page we’re interested in... doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove')) # Do funky things with it using Nokogiri::XML::Node methods... #### # Search for nodes by css doc.css('h3.r a.l').each do |link| puts link.content end
See Nokogiri::XML::Node#css for more information about CSS searching. See Nokogiri::XML::Node#xpath for more information about XPath searching.
LIBXML_PARSER_VERSION | = | LibXML.__xmlParserVersion().read_pointer.read_string | ||
LIBXML_VERSION | = | LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{|j|j.to_i}.join(".") | ||
VERSION | = | '1.3.1' | The version of Nokogiri you are using | |
VERSION_INFO | = | {} | More complete version information about libxml |
Parse HTML. Convenience method for Nokogiri::HTML::Document.parse
Parse a document and add the Slop decorator. The Slop decorator implements method_missing such that methods may be used instead of CSS or XPath. For example:
doc = Nokogiri::Slop(<<-eohtml) <html> <body> <p>first</p> <p>second</p> </body> </html> eohtml assert_equal('second', doc.html.body.p[1].text)
Parse XML. Convenience method for Nokogiri::XML::Document.parse
Create a Nokogiri::XSLT::Stylesheet with stylesheet.
Example:
xslt = Nokogiri::XSLT(File.read(ARGV[0]))