# XML in rails

**URL:** <https://www.ruby-forum.com/t/xml-in-rails/181808>\
**Category:** Rails\
**Created:** [January 18, 2010, 5:08pm UTC](https://www.ruby-forum.com/t/xml-in-rails/181808 "2010-01-18T17:08:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@sujay](https://www.ruby-forum.com/u/sujay)\
**Post date:** [January 18, 2010, 5:08pm UTC](https://www.ruby-forum.com/t/xml-in-rails/181808/1 "2010-01-18T17:08:39Z")

</div>

I have an XML file containing data which I need to access in the  
controller. For example, the XML file contains cpu usage and cpu load  
and other such information. I need to collect this information into a  
controller and display it in a graph (chartdirector). How do I get the  
values from the XML file to the controller?

---

<div class="post-metadata">

**Author:** ![sujay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@sujay](https://www.ruby-forum.com/u/sujay)\
**Post date:** [January 18, 2010, 5:17pm UTC](https://www.ruby-forum.com/t/xml-in-rails/181808/2 "2010-01-18T17:17:16Z")

</div>

On Mon, Jan 18, 2010 at 8:08 AM, Sujay B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have an XML file containing data which I need to access in the  
> controller. For example, the XML file contains cpu usage and cpu load  
> and other such information. I need to collect this information into a  
> controller and display it in a graph (chartdirector). How do I get the  
> values from the XML file to the controller?

Open the file and use Nokogiri (gem) to parse the XML.

---

<div class="post-metadata">

**Author:** ![sujay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@sujay](https://www.ruby-forum.com/u/sujay)\
**Post date:** [January 18, 2010, 5:19pm UTC](https://www.ruby-forum.com/t/xml-in-rails/181808/3 "2010-01-18T17:19:02Z")

</div>

Did you checkout the nokogiri plugin? Also there is ReXML

---

<div class="post-metadata">

**Author:** ![sujay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@sujay](https://www.ruby-forum.com/u/sujay)\
**Post date:** [January 18, 2010, 11:06pm UTC](https://www.ruby-forum.com/t/xml-in-rails/181808/4 "2010-01-18T23:06:45Z")

</div>

Where would you recommend putting all of the parsing code, in a Model  
or Controller? I’m very new at working with MVC, but to be it seems  
that an XML document, being a representation of data, would be handled  
by a Model. Am I wrong? Thanks!

On Jan 18, 11:16Â am, Hassan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sujay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@sujay](https://www.ruby-forum.com/u/sujay)\
**Post date:** [January 18, 2010, 11:12pm UTC](https://www.ruby-forum.com/t/xml-in-rails/181808/5 "2010-01-18T23:12:36Z")

</div>

2010/1/18 Seirie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Where would you recommend putting all of the parsing code, in a Model  
> or Controller? I’m very new at working with MVC, but to be it seems  
> that an XML document, being a representation of data, would be handled  
> by a Model. Am I wrong? Thanks!

You are completely correct, put the reading and parsing in a model  
that is not derived from AR::base

Colin
