Re: [nokogiri-talk] Upgrade from Nokogiri 1.5.0 to 1.5.7

12 views
Skip to first unread message

Mike Dalessio

unread,
Apr 25, 2013, 6:34:54 PM4/25/13
to nokogiri-talk

Hello there!


On Tue, Apr 23, 2013 at 9:53 PM, Hospira <yen.s...@gmail.com> wrote:

Hi,

I am trying to change the contents of a the HTML tag called "value".
In Nokogiri 1.5.0 the following statement was working just fine:

controlXml.elements.at("value").text = "some text"

but after upgrade to Nokogiri 1.5.7 it fails

Fails how? Can you be more specific?

I've tried to reproduce this with the following script:

#!/usr/bin/env ruby
require "nokogiri"
puts Nokogiri::VERSION
doc = Nokogiri::XML %q{<root><foo></foo></root>}
doc.at("foo").text = "bleah"
puts doc.to_html

and, using Nokoiri 1.6.0.rc1, I get this output:

1.6.0.rc1
/home/miked/foo.rb:7:in `<main>': undefined method `text=' for #<Nokogiri::XML::Element:0x11c950c name="foo"> (NoMethodError)

Is this the failure you're referring to?

When I run the same script with Nokogiri 1.5.0, I get the same error:

1.5.0
./foo.rb:5: undefined method `text=' for #<Nokogiri::XML::Element:0x3f854ebdb290 name="foo"> (NoMethodError)

So I'm confused as to why you think this ever worked in Nokogiri 1.5.0.
 

and works only if I make the above statement is replaced as follows:

controlXml.at_css("value").content = "some text"
controlXml.to_html

This happens only if I try reassignment of the content because if I try extracting the content using ".text", it works fine. For example the following works:

text = controlXml.elements.at("value").text
puts text

Can someone please tell me the reason for this?

Node#text, Node#content and Node#content= are all methods (or aliases to methods). Node#text= is not.
 

I have many places in my code where I reassign the contents using ".text" which is failing. Has something been made obsolete during the upgrade? Is there some way that I can make the ".text" work? Please help.

I'm not sure I understand, because as I said, Node#text= was never a method ever supported in any version of Nokogiri. Use #content= instead, please. 

Thanks,
Hospira

--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at http://groups.google.com/group/nokogiri-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Hospira

unread,
Apr 29, 2013, 12:33:10 AM4/29/13
to nokogi...@googlegroups.com
Hello Mike,

Thank you for your email!

I got this error in Nokogiri 1.5.7:

C:/.../*.rb:311:in `view_message_at_index': undefined method `text=' for #<Nokogiri::XML::Element:0x20e4928> (NoMethodError)

Anyway, thank you for your reply. I will modify Nokogiri#text = to Nokogiri#content =

Regards,
Semone.
Reply all
Reply to author
Forward
0 new messages