Tamara Temple wrote in post #1111724:
> Love U Ruby <[email protected]> wrote:
>> <meta charset="UTF-8">
>> </head>
>> eof

You realized my exact pain area. I always confused about the use of the 
below two methods:

**Nokogiri::HTML::Document.new
**Nokogiri::HTML::Document.parse

==================================


require "nokogiri"
require 'pp'

doc = Nokogiri::HTML::Document.parse "<title> Save the page! </title>"
doc.class # => Nokogiri::HTML::Document
doc
# => #(Document:0x4592d16 {
#      name = "document",
#      children = [
#        #(DTD:0x4592244 { name = "html" }),
#        #(Element:0x458dd7a {
#          name = "html",
#          children = [
#            #(Element:0x45871d2 {
#              name = "head",
#              children = [
#                #(Element:0x458161a {
#                  name = "title",
#                  children = [ #(Text " Save the page! ")]
#                  })]
#              })]
#          })]
#      })

doc = Nokogiri::HTML::Document.new("<title> Save the page! </title>")
doc.class # => Nokogiri::HTML::Document
doc
# => #(Document:0x4578128 {
#      name = "document",
#      children = [ #(DTD:0x45714fe { name = "html" })]
#      })


Both the document creating `Nokogiri::HTML::Document` object. But when I 
am printing those,seeing the output differently. Now my questions are -

(a) why does `Nokogiri::HTML::Document.parse` and 
`Nokogiri::HTML::Document.new` creating the document object differently?

(b) What is the proper use-case about their uses mean when should I need 
to think/what method to use?


Please help me to digest this basic food. :) :)

Thanks

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/82c1392f62c2bdfef54e6886bcfd98c9%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to