# REXML - XML query only returning one (last) result

**URL:** <https://www.ruby-forum.com/t/rexml-xml-query-only-returning-one-last-result/115880>\
**Category:** Rails\
**Created:** [September 29, 2007, 8:10pm UTC](https://www.ruby-forum.com/t/rexml-xml-query-only-returning-one-last-result/115880 "2007-09-29T20:10:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giant\_Jam\_Sandwich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d6d6ee/32.png) [@Giant\_Jam\_Sandwich](https://www.ruby-forum.com/u/Giant_Jam_Sandwich)\
**Post date:** [September 29, 2007, 8:10pm UTC](https://www.ruby-forum.com/t/rexml-xml-query-only-returning-one-last-result/115880/1 "2007-09-29T20:10:47Z")

</div>

I’m really new to Ruby on Rails, and I’m trying to read an XML file  
with REXML. No matter what I try, I am only getting the last result  
returned from my query. I should be getting 365 results. Here is the  
code:

include REXML  
require ‘rexml/document’  
require ‘rexml/xpath’

class MakeFootprintController \< ApplicationController  
def index  
file = File.new("#{RAILS\_ROOT}/xml/footprints.xml")  
doc = Document.new(file)  
doc.each\_element(’//day’) { |day|  
render\_text day  
}  
end  
end

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Giant\_Jam\_Sandwich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d6d6ee/32.png) [@Giant\_Jam\_Sandwich](https://www.ruby-forum.com/u/Giant_Jam_Sandwich)\
**Post date:** [September 29, 2007, 9:56pm UTC](https://www.ruby-forum.com/t/rexml-xml-query-only-returning-one-last-result/115880/2 "2007-09-29T21:56:47Z")

</div>

On 29 Sep 2007, at 19:10, Giant Jam Sandwich wrote:

> I’m really new to Ruby on Rails, and I’m trying to read an XML file  
> with REXML. No matter what I try, I am only getting the last result  
> returned from my query. I should be getting 365 results. Here is the  
> code:

By default, render\_text sets the response body (instead of appending  
to it), so all your calls to render\_text are overwriting each other,  
render\_text takes extra parameters that allow you to override this  
Calling render\_text more than once isn’t really right though. (You  
could use a partial or something).

Fred

---

<div class="post-metadata">

**Author:** ![Giant\_Jam\_Sandwich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d6d6ee/32.png) [@Giant\_Jam\_Sandwich](https://www.ruby-forum.com/u/Giant_Jam_Sandwich)\
**Post date:** [October 2, 2007, 3:37pm UTC](https://www.ruby-forum.com/t/rexml-xml-query-only-returning-one-last-result/115880/3 "2007-10-02T15:37:02Z")

</div>

Thanks Fred!

On Sep 29, 2:56 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
