From: Phrogz Date: 2007-03-23T02:10:10+09:00 Subject: Re: Pulling text from elements with REXML On Mar 22, 11:02 am, Paul Willis wrote: > Gavin Kistner wrote: > > att = XPath.first( doc, '//kid/@stuff' ) > > I don't know what the XPath syntax is to select the value of an > > attribute directly. I'd be interested to know if someone else knows it. > > Cheers, it was the kid/@stuff I needed... > > puts XPath.first( doc, '/root/kid/@stuff' ) > > #=> some-other-text Nice, I didn't realize that REXML::Attribute had such different output for #inspect versus #to_s. It's nice, then, that you don't need to call .value in this particular case. Just be aware that without the .value call you still have an Attribute instance that can just be treated as a string in some areas: att = XPath.first( doc, '//kid/@stuff' ) puts att #=> some-other-text puts att.value + '-more' #=> some-other-text-more puts att + "-more" #=> tmp.rb:17: undefined method `+' for stuff='some-other-text':REXML::Attribute (NoMethodError)