On Fri, Apr 13, 2007 at 08:45:08PM +0900, chickenkiller wrote:
> On Apr 13, 12:10 pm, Bontina Chen <abonc... / gmail.com> wrote:
> > Lionel Orry wrote:
> > > On Apr 13, 10:11 am, Bontina Chen <abonc... / gmail.com> wrote:
> > >> <dc:creator>morwyn</dc:creator>
> >
> > >> but I got
> > >> Posted viahttp://www.ruby-forum.com/.
> > > replace innerTEXT by inner_html:
> >
> > > (doc/"item").each do |t|
> > >    puts (t/"dc:subject").inner_html
> > > end
> >
> > > regards
> > > Lionel
> >
> > Thx for your response , but I still get
> > <dc:subject>html 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)

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:subject>html
> 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.

irb(main):003:0> p (1+3).to_s
"4"
=> nil
irb(main):004:0> p(1+3).to_s
4
=> ""

In the first case, this is   p( (1+3).to_s )

In the second case, this is  ( p(1+3) ).to_s   # i.e. nil.to_s