public
Description: Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser with XPath and CSS selector support.
Homepage: http://nokogiri.org/
Clone URL: git://github.com/tenderlove/nokogiri.git
nokogiri / lib / nokogiri.rb
a913af57 » flavorjones 2009-04-23 added Nokogiri::VERSION_INF... 1 # -*- coding: utf-8 -*-
7f2ae51a » tenderlove 2009-02-13 loading the native portions... 2 # Modify the PATH on windows so that the external DLLs will get loaded.
3 ENV['PATH'] = [File.expand_path(
4 File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
454c543f » tenderlove 2009-05-07 adding fat binary codes 5 ), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /(mswin|mingw)/i
7f2ae51a » tenderlove 2009-02-13 loading the native portions... 6
836e526a » flavorjones 2009-04-30 FFI branch squash-merged in... 7 if ENV['NOKOGIRI_FFI'] || RUBY_PLATFORM =~ /java/
b2975514 » flavorjones 2009-05-11 requiring ruby-ffi gem 0.4.... 8 gem 'ffi', '>=0.4.0' unless RUBY_PLATFORM =~ /java/
836e526a » flavorjones 2009-04-30 FFI branch squash-merged in... 9 require 'ffi'
10 require 'nokogiri/ffi/libxml'
11 else
2dd18529 » tenderlove 2009-05-24 making fat binaries easy wi... 12 require 'nokogiri/nokogiri'
836e526a » flavorjones 2009-04-30 FFI branch squash-merged in... 13 end
7f2ae51a » tenderlove 2009-02-13 loading the native portions... 14
08450f39 » tenderlove 2008-08-19 auto generating the IDL int... 15 require 'nokogiri/version'
1f2d6372 » tenderlove 2009-05-13 adding a libxml2 version wa... 16 require 'nokogiri/version_warning'
597861f0 » jmhodges 2009-02-03 providing a central Nokogir... 17 require 'nokogiri/syntax_error'
34102644 » tenderlove 2008-07-18 adding the html and xml parser 18 require 'nokogiri/xml'
5ff03ff3 » tenderlove 2008-08-24 adding xslt support 19 require 'nokogiri/xslt'
34102644 » tenderlove 2008-07-18 adding the html and xml parser 20 require 'nokogiri/html'
221a44e7 » tenderlove 2008-09-15 adding decoration to nokogi... 21 require 'nokogiri/decorators'
38d3bfbd » tenderlove 2008-09-17 starting the css selector ast 22 require 'nokogiri/css'
221a44e7 » tenderlove 2008-09-15 adding decoration to nokogi... 23 require 'nokogiri/html/builder'
8a45571f » flavorjones 2008-09-15 added Nokogiri(), Nokogiri.... 24 require 'nokogiri/hpricot'
35cace6b » tenderlove 2008-10-29 fixing up win32 build, addi... 25
9d4a78eb » tenderlove 2009-03-13 adding some documentation, ... 26 # Nokogiri parses and searches XML/HTML very quickly, and also has
27 # correctly implemented CSS3 selector support as well as XPath support.
28 #
29 # Parsing a document returns either a Nokogiri::XML::Document, or a
30 # Nokogiri::HTML::Document depending on the kind of document you parse.
31 #
32 # Here is an example:
33 #
34 # require 'nokogiri'
35 # require 'open-uri'
36 #
37 # # Get a Nokogiri::HTML:Document for the page we’re interested in...
38 #
39 # doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
40 #
41 # # Do funky things with it using Nokogiri::XML::Node methods...
42 #
43 # ####
44 # # Search for nodes by css
45 # doc.css('h3.r a.l').each do |link|
46 # puts link.content
47 # end
48 #
49 # See Nokogiri::XML::Node#css for more information about CSS searching.
50 # See Nokogiri::XML::Node#xpath for more information about XPath searching.
9eebaa08 » tenderlove 2008-07-14 breaking up nokogiri 51 module Nokogiri
e7f98b6c » tenderlove 2008-07-14 initial checkin 52 class << self
8b9daefb » tenderlove 2008-11-30 making sure that sloppy css... 53 ###
54 # Parse an HTML or XML document. +string+ contains the document.
93761f99 » tenderlove 2008-10-15 adding parser constants and... 55 def parse string, url = nil, encoding = nil, options = nil
449e7c5a » tenderlove 2008-07-18 working on new api 56 doc =
57 if string =~ /^\s*<[^Hh>]*html/i # Probably html
9a18d602 » flavorjones 2009-06-08 Replacing parse option "mag... 58 Nokogiri::HTML::Document.parse(string, url, encoding, options || XML::ParseOptions::DEFAULT_HTML)
449e7c5a » tenderlove 2008-07-18 working on new api 59 else
9a18d602 » flavorjones 2009-06-08 Replacing parse option "mag... 60 Nokogiri::XML::Document.parse(string, url, encoding, options || XML::ParseOptions::DEFAULT_XML)
449e7c5a » tenderlove 2008-07-18 working on new api 61 end
62 yield doc if block_given?
63 doc
e7f98b6c » tenderlove 2008-07-14 initial checkin 64 end
8a45571f » flavorjones 2008-09-15 added Nokogiri(), Nokogiri.... 65
acddc4a8 » tenderlove 2009-04-25 adding an rdoc test and add... 66 ###
67 # Create a new Nokogiri::XML::DocumentFragment
93761f99 » tenderlove 2008-10-15 adding parser constants and... 68 def make input = nil, opts = {}, &blk
1c4e553b » flavorjones 2008-09-16 implemented NodeSet.wrap() ... 69 if input
0dfe0255 » tenderlove 2009-02-05 HTML.fragment now returns a... 70 Nokogiri::HTML.fragment(input).children.first
1c4e553b » flavorjones 2008-09-16 implemented NodeSet.wrap() ... 71 else
903a28d3 » tenderlove 2008-09-25 fixing warning 72 Nokogiri(&blk)
1c4e553b » flavorjones 2008-09-16 implemented NodeSet.wrap() ... 73 end
74 end
acddc4a8 » tenderlove 2009-04-25 adding an rdoc test and add... 75
8b9daefb » tenderlove 2008-11-30 making sure that sloppy css... 76 ###
77 # Parse a document and add the Slop decorator. The Slop decorator
78 # implements method_missing such that methods may be used instead of CSS
79 # or XPath. For example:
80 #
81 # doc = Nokogiri::Slop(<<-eohtml)
82 # <html>
83 # <body>
84 # <p>first</p>
85 # <p>second</p>
86 # </body>
87 # </html>
88 # eohtml
89 # assert_equal('second', doc.html.body.p[1].text)
90 #
46be2582 » jbarnette 2008-11-26 Nokogiri::Slop(xml) provide... 91 def Slop(*args, &block)
92 Nokogiri(*args, &block).slop!
93 end
8a45571f » flavorjones 2008-09-15 added Nokogiri(), Nokogiri.... 94 end
95 end
96
acddc4a8 » tenderlove 2009-04-25 adding an rdoc test and add... 97 ###
98 # Parser a document contained in +args+. Nokogiri will try to guess what
99 # type of document you are attempting to parse. For more information, see
100 # Nokogiri.parse
101 #
102 # To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
8a45571f » flavorjones 2008-09-15 added Nokogiri(), Nokogiri.... 103 def Nokogiri(*args, &block)
104 if block_given?
1c4e553b » flavorjones 2008-09-16 implemented NodeSet.wrap() ... 105 builder = Nokogiri::HTML::Builder.new(&block)
a02964e4 » tenderlove 2009-02-13 adding to_xhtml using xmlsa... 106 return builder.doc.root
8a45571f » flavorjones 2008-09-15 added Nokogiri(), Nokogiri.... 107 else
33ab946e » tenderlove 2008-11-22 delegating Nokogiri() to th... 108 Nokogiri.parse(*args)
e7f98b6c » tenderlove 2008-07-14 initial checkin 109 end
110 end