# Problems with text() and REXML

**URL:** <https://www.ruby-forum.com/t/problems-with-text-and-rexml/158219>\
**Category:** Ruby\
**Created:** [January 20, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/problems-with-text-and-rexml/158219 "2009-01-20T18:49:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [January 20, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/problems-with-text-and-rexml/158219/1 "2009-01-20T18:49:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [January 20, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/problems-with-text-and-rexml/158219/2 "2009-01-20T23:30:48Z")

</div>

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  
  
  
  
the text  
  
  
  
XML

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

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

Kind regards

robert
