[from morwyn] * HTML for the Conceptually Challenged
http://del.icio.us/url/50666d1a3fe2b942b20819ec2919d2b7#morwyn
HTML for the Conceptually Challenged. Very basic tutorial,
plainly worded for people who hate to read instructions.
morwyn
2006-10-10T07:28:28Z
html imported webpagedesign
I’m trying to get the content from dc:subject like this
On Fri, Apr 13, 2007 at 08:45:08PM +0900, chickenkiller wrote:
puts (t/“dc:subject”).inner_html
In fact, inner_text works as well. But you should have a look at the
warnings from ruby! The inner_text or inner_html function is applied
to ‘puts (t/“dc:subject”)’ return object, which is nil.
So a warning appears:
rdf.rb:6: undefined method `inner_html’ for nil:NilClass
(NoMethodError)
That’s not a warning, that’s an exception, and the program will
terminate at
that point. The OP didn’t mention any errors.
but ‘puts (t/“dc:subject”)’ is executed, and so ‘dc:subjecthtml
internet tutorial web</dc:subject>’ is displayed anyway. Therefore I
recommend using a few parentheses there:
puts((t/“dc:subject”).inner_text)
and it should work well this time.
Next time, look at the warnings!!!
Good point, but it was OK the way he wrote it, with a space after puts.
Thx for your response , but I still get dc:subjecthtml internet tutorial web</dc:subject>
–
Posted viahttp://www.ruby-forum.com/.
In fact, inner_text works as well. But you should have a look at the
warnings from ruby! The inner_text or inner_html function is applied
to ‘puts (t/“dc:subject”)’ return object, which is nil.
So a warning appears:
rdf.rb:6: undefined method `inner_html’ for nil:NilClass
(NoMethodError)
but ‘puts (t/“dc:subject”)’ is executed, and so ‘dc:subjecthtml
internet tutorial web</dc:subject>’ is displayed anyway. Therefore I
recommend using a few parentheses there:
(doc/“item”).each do |t|
Posted viahttp://www.ruby-forum.com/.
In fact, inner_text works as well. But you should have a look at the
warnings from ruby! The inner_text or inner_html function is applied
to ‘puts (t/“dc:subject”)’ return object, which is nil.
So a warning appears:
rdf.rb:6: undefined method `inner_html’ for nil:NilClass
(NoMethodError)
That’s not a warning, that’s an exception, and the program will terminate at
that point. The OP didn’t mention any errors.
Indeed I use the term ‘warning’ VERY abusively - I apologize for this.
This is an exception and nothing else.
In the second case, this is ( p(1+3) ).to_s # i.e. nil.to_s
mmmh… interesting… It seems that the problem arises when in a
block:
output text in comments…
require ‘hpricot’
doc = Hpricot(File.open(“rdf.xhtml”))
puts (doc/“item”/“dc:subject”).inner_text
html imported webpagedesign
(doc/“item”).each do |t|
puts((t/“dc:subject”).inner_text)
end
html imported webpagedesign
(doc/“item”).each do |t|
puts (t/“dc:subject”).inner_text
end
On Fri, Apr 13, 2007 at 10:40:05PM +0900, chickenkiller wrote:
(doc/“item”).each do |t|
Any ideas?
Hmm, looks like this should be something that can be replicated without
hpricot.
$ cat x.rb
x = 3
puts (x-5).abs
1.times do
puts (x-5).abs
end
$ ruby -v
ruby 1.8.4 (2005-12-24) [i486-linux]
$ ruby x.rb
x.rb:5: warning: don’t put space before argument parentheses
2
-2
x.rb:5: undefined method `abs’ for nil:NilClass (NoMethodError)
from x.rb:4
$
Congratulations, I think you’ve found a bug in the parser I’ll post
this
example to ruby-core.