Nokogiri : Modifying Nodes and Attributes

In my test i do have :

Because i know this declaration is false from Lynx saying it is UTF-8, i want to change the content attribute by : meta=doc.at_xpath("/html/head/meta") meta['content']="text/html; charset=UTF-8" if !meta.nil? && meta['http-equiv'].downcase=='content-type'

however, printing meta gives always :

that's to say, no change at all.

Is this behaviour implied by the fact the meta tag isn’t self closed, ie
not ending by " />" ???

If yes, in that case i could unling all meta tags and create a good one
?
No quicker solution ?

Une B

2011/5/31 Une B. [email protected]

In my test i do have :

Because i know this declaration is false from Lynx saying it is UTF-8, i
want to change the content attribute by :
meta=doc.at_xpath(“/html/head/meta”)
meta[‘content’]=“text/html; charset=UTF-8” if !meta.nil? &&
meta[‘http-equiv’].downcase==‘content-type’

Have you tried using Document#meta_encoding= ?

See http://nokogiri.org/search?q=meta_encoding%3D

Also, prefer nokogiri-talk to ruby-talk for Nokogiri questions. Thank
you!

=?ISO-8859-1?Q?Une_B=E9vue?= wrote in post #1002177:

however, printing meta gives always :

that's to say, no change at all.
  1. People are going to have to reproduce what you did. Saying you
    “printed” meta does not cut it: you have to show the code that actually
    does that.

  2. According to the Nokogiri docs for Nokogiri::HTML::Document

===
Public Instance Methods:

meta_encoding=(encoding)

Set the meta tag encoding for this document. If there is no meta content
tag, nil is returned and the encoding is not set.

Mike D. [email protected] wrote:

Have you tried using Document#meta_encoding= ?

No, I’ll look at…

I did a workaround in between, using a gsub…

See http://nokogiri.org/search?q=meta_encoding%3D

Also, prefer nokogiri-talk to ruby-talk for Nokogiri questions. Thank you!

OK, i’ve suscribed to this list.