Problems with text() and REXML

K

Kenneth McDonald

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
 
R

Robert Klemme

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top