Love U Ruby <[email protected]> wrote:
> Still I am getting `nil`.
> 
> doc = Nokogiri::HTML::Document.new("<title> Save the page! </title>")
> doc.meta_encoding="<meta http-equiv=\"Content-Type\"
> content=\"text/html; charset=utf-8\">"
> doc.meta_encoding # => nil

You're confusing #new with #parse, as well as what the input to
#meta_encoding should be.

irb(main):027:0> doc = Nokogiri::HTML::Document.parse "<title> Save the page! 
</title>"
#<Nokogiri::HTML::Document:0x4c2aa20 name="document" 
children=[#<Nokogiri::XML::DTD:0x4c35fc4 name="html">, 
#<Nokogiri::XML::Element:0x4c35a38 name="html" 
children=[#<Nokogiri::XML::Element:0x4c3565a name="head" 
children=[#<Nokogiri::XML::Element:0x4c35470 name="title" 
children=[#<Nokogiri::XML::Text:0x4c35196 " Save the page! ">]>]>]>]>
irb(main):028:0> puts doc
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
"http://www.w3.org/TR/REC-html40/loose.dtd";>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Save the page! </title>
</head></html>
nil
irb(main):029:0> doc.meta_encoding
"UTF-8"
irb(main):030:0> doc.meta_encoding="ISO-8599-2"
"ISO-8599-2"
irb(main):031:0> doc.meta_encoding
"ISO-8599-2"

Also, since you are parsing fragments instead of documents, you really
should be using DocumentFragment instead of Document.

irb(main):032:0> docf = Nokogiri::HTML::DocumentFragment.parse "<title> Save 
the Page! </title>"
#<Nokogiri::HTML::DocumentFragment:0x4d30514 name="#document-fragment" 
children=[#<Nokogiri::XML::Element:0x4d303ca name="title" 
children=[#<Nokogiri::XML::Text:0x4d300a0 " Save the Page! ">]>]>
irb(main):033:0> puts docf
<title> Save the Page! </title>
nil
irb(main):034:0> docf.respond_to?(:meta_encoding)
false

Since the encoding only makes sense when you assemble the entire
document to send it out to the browser, fragments don't care.

What remains is still how to get Nokogiri to recognize and emit HTML5.

-- 
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/51b349d4.8a823c0a.4372.fffffd24%40mx.google.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to