title: Displaying XML in a Rails view
body: <p>In my Rails app, I'm trying to display the contents of an XML file in a view partial template. I want to display the actual markup of the entire XML file -- tags, properly formatted with indentation, etc. -- not just the text data, or a specific node.</p>
  
  <p>The XML file is located on another server, so first I have to grab the file. Here's my approach so far, which displays the tags but doesn't format them -- it just displays in one unbroken line.</p>
  
  <p>In my controller:</p>
  
  <pre><code>@xml_file_path = 'some file path'
  @response = Typhoeus::Request.get(@xml_file_path)
  </code></pre>
  
  <p>And in the view template:</p>
  
  <pre><code>&lt;%= render :text =&gt; @response.body, :content_type =&gt; 'application/xml' %&gt;
  </code></pre>
  
  <p>This results in the XML displaying on a single line, like so:</p>
  
  <pre><code>&lt;mods:mods&gt;&lt;mods:physicalDescription&lt;mods:internetMediaType&gt;image/jpeg&lt;/mods:internetMediaType&gt;&lt;/mods:physicalDescription&gt;&lt;/mods:mods&gt;
  </code></pre>
  
  <p>But I want it to display to the user with the line breaks and indentation, etc, like so:</p>
  
  <pre><code>&lt;mods:mods&gt;
    &lt;mods:physicalDescription&gt;
      &lt;mods:internetMediaType&gt;image/jpeg&lt;/mods:internetMediaType&gt;
    &lt;/mods:physicalDescription&gt;
  &lt;/mods:mods&gt;
  </code></pre>
  
  <p>How can I accomplish this? I'm thinking that '<code>render :text</code>' is not the right approach here, but not sure what would be better. Any advice appreciated. I'm pretty new to Rails.</p>
  
  <p>Thanks in advance!</p>