Forum: Ruby Problems with text() and REXML

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kenneth McDonald (Guest)
on 2009-01-20 19:49
(Received via mailing list)
I'm finding that in REXML, the XPath selector "//abstract//style"
correctly selects nodes in the tree, but "//abstract//style//text()"
does not then extract the text from those nodes. Is this a known
problem with XPath in Rexml?

Thanks,
Ken
Robert K. (Guest)
on 2009-01-21 00:30
(Received via mailing list)
On 20.01.2009 18:46, Kenneth McDonald wrote:
> I'm finding that in REXML, the XPath selector "//abstract//style"
> correctly selects nodes in the tree, but "//abstract//style//text()"
> does not then extract the text from those nodes. Is this a known
> problem with XPath in Rexml?

You're abusing "//".  This works for me

#!/bin/env ruby

require 'rexml/document'

doc = REXML::Document.new <<XML
<root>
   <abstract>
     <style>
       the text
     </style>
   </abstract>
</root>
XML

REXML::XPath.each(doc, '//abstract/style/text()') do |elm|
   p elm
end

See also
http://www.w3schools.com/xpath/
http://www.zvon.org/xxl/XPathTutorial/General/examples.html

Kind regards

  robert
This topic is locked and can not be replied to.