# Rendering XML to a web page

**URL:** <https://www.ruby-forum.com/t/rendering-xml-to-a-web-page/111545>\
**Category:** Rails\
**Created:** [August 8, 2007, 2:34pm UTC](https://www.ruby-forum.com/t/rendering-xml-to-a-web-page/111545 "2007-08-08T14:34:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![magiclava](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@magiclava](https://www.ruby-forum.com/u/magiclava)\
**Post date:** [August 8, 2007, 2:34pm UTC](https://www.ruby-forum.com/t/rendering-xml-to-a-web-page/111545/1 "2007-08-08T14:34:55Z")

</div>

I have a couple of issues…

First my XML looks like this:  
  
…  
…  
…  
…  
…  
…Here is the answer to your question  
…  
…  
…Here is the question  
…  
…

So basically i would like to output each question within the  
questionaire along with the answer to a web page. i.e. Here is  
the question Here is the answer to your question

My CONTROLLER looks like this:

def show\_questionaire  
require ‘rexml/document’  
@xml\_q = Questionaire.find(params[:id]) #get the xml string from the  
database  
@doc\_xml = REXML::Document.new(@xml\_q.que\_result)  
end

My VIEW currently looks like this:  
\<% @doc\_xml.elements.each("//question/text) do |element| %\>

 \<%= element[0] %\> 
\<% end %\>

This outputs the list of questions, but i can’t seem to understand how  
to display the answer in the same loop…

Please help,

Thanks,

Mike  
P.S. i’ve read the REXML tutorial, but again i can’t see how to get  
two elements at the same time…

---

<div class="post-metadata">

**Author:** ![magiclava](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@magiclava](https://www.ruby-forum.com/u/magiclava)\
**Post date:** [August 9, 2007, 9:20am UTC](https://www.ruby-forum.com/t/rendering-xml-to-a-web-page/111545/2 "2007-08-09T09:20:53Z")

</div>

> First my XML looks like this:  
>   
> …  
> …  
> …  
> …  
> …  
> …Here is the answer to your question  
> …  
> …  
> …Here is the question  
> …  
> …

> My VIEW currently looks like this:  
> \<% @doc\_xml.elements.each("//question/text) do |element| %\>
> 
> \<%= element[0] %\> 
> \<% end %\>

One way to do it would be to change your query to return the question  
nodes, and then access the child text and items/item/text node(s) from  
there…
