# Display XML as text

**URL:** <https://www.ruby-forum.com/t/display-xml-as-text/163457>\
**Category:** Rails\
**Created:** [March 20, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/display-xml-as-text/163457 "2009-03-20T15:44:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [March 20, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/display-xml-as-text/163457/1 "2009-03-20T15:44:24Z")

</div>

I have question regarding render :text … I read the conten of XML file  
and display it using render :text … but the content only is shown and  
not the entire xml file … How do I get the xml file display as xml  
file in the output?

to state with an example the problem I have if the xml is  
dog and I use render :text then output is only dog… I  
want to output entire dog

Need help

Regards,  
Sudhindra

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [March 20, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/display-xml-as-text/163457/2 "2009-03-20T16:37:20Z")

</div>

Hi,

are you sure that this is real output? Try using wget or curl to see  
what real output is. Or maybe look into page source? (Ctrl + V on  
firefox). It might be that your browser is not displaying xml tags  
just ignoring them, and displays only what’s inside.

Best,  
H

On 20 Mar, 15:44, Sudhi K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [March 20, 2009, 5:08pm UTC](https://www.ruby-forum.com/t/display-xml-as-text/163457/3 "2009-03-20T17:08:28Z")

</div>

On Fri, Mar 20, 2009 at 7:44 AM, Sudhi K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> to state with an example the problem I have if the xml is  
> dog and I use render :text then output is only dog… I  
> want to output entire dog

You need to escape the angle brackets, e.g.

\<% @xml = “dog” %\>

\<%=h @xml %\>

Try the above with and without the ‘h’.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![sudhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@sudhi](https://www.ruby-forum.com/u/sudhi)\
**Post date:** [March 20, 2009, 5:40pm UTC](https://www.ruby-forum.com/t/display-xml-as-text/163457/4 "2009-03-20T17:40:07Z")

</div>

Why don’t you use the render :xml?

Rendering XML

Rendering XML sets the content type to application/xml.

# Renders ‘David’

render :xml =\> {:name =\> “David”}.to\_xml

Itâ€˜s not necessary to  
call[http://api.rubyonrails.org/classes/ActionController/Base.html#M000612](http://api.rubyonrails.org/classes/ActionController/Base.html#M000612)  
to\_xml on the object you want to  
render[http://api.rubyonrails.org/classes/ActionController/Base.html#M000633](http://api.rubyonrails.org/classes/ActionController/Base.html#M000633),  
since  
render[http://api.rubyonrails.org/classes/ActionController/Base.html#M000633](http://api.rubyonrails.org/classes/ActionController/Base.html#M000633)will  
automatically do that for you:

# Also renders ‘David’

render :xml =\> {:name =\> “David”}

On Fri, Mar 20, 2009 at 12:07 PM, Hassan S. \<
