# Processing an XML list in a controller

**URL:** <https://www.ruby-forum.com/t/processing-an-xml-list-in-a-controller/176785>\
**Category:** Rails\
**Created:** [October 6, 2009, 8:28am UTC](https://www.ruby-forum.com/t/processing-an-xml-list-in-a-controller/176785 "2009-10-06T08:28:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saxosurfin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@saxosurfin](https://www.ruby-forum.com/u/saxosurfin)\
**Post date:** [October 6, 2009, 8:28am UTC](https://www.ruby-forum.com/t/processing-an-xml-list-in-a-controller/176785/1 "2009-10-06T08:28:21Z")

</div>

Hi

I have posted an XML list to a rails controller from a flex client  
along the lines of

The itemList is a parmeter passed to the controller, what I would like  
to know is how I process the itemList as an XML entity. What I want to  
do is loop through the items, find the object for the id and update  
the value attribute based on the value from the XML list.

Is there an example around of doing a similar thing or if someone can  
provide an answer I would much appreciate it.

---

<div class="post-metadata">

**Author:** ![saxosurfin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@saxosurfin](https://www.ruby-forum.com/u/saxosurfin)\
**Post date:** [October 6, 2009, 1:04pm UTC](https://www.ruby-forum.com/t/processing-an-xml-list-in-a-controller/176785/2 "2009-10-06T13:04:57Z")

</div>

suggesting gem nokogiri too

Sijo

---

<div class="post-metadata">

**Author:** ![saxosurfin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@saxosurfin](https://www.ruby-forum.com/u/saxosurfin)\
**Post date:** [October 6, 2009, 12:31pm UTC](https://www.ruby-forum.com/t/processing-an-xml-list-in-a-controller/176785/3 "2009-10-06T12:31:57Z")

</div>

Hi,

On Mon, 2009-10-05 at 23:26 -0700, saxosurfin wrote:

> The itemList is a parmeter passed to the controller, what I would like  
> to know is how I process the itemList as an XML entity. What I want to  
> do is loop through the items, find the object for the id and update  
> the value attribute based on the value from the XML list.
> 
> Is there an example around of doing a similar thing or if someone can  
> provide an answer I would much appreciate it.

Check out Hpricot and REXml. Google for examples. Come back with  
specific questions if you have problems.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![saxosurfin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@saxosurfin](https://www.ruby-forum.com/u/saxosurfin)\
**Post date:** [October 13, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/processing-an-xml-list-in-a-controller/176785/4 "2009-10-13T20:10:24Z")

</div>

If that’s actually what’s in params, somebody’s already parsed the  
XML. No REXML needed…

–Matt

---

<div class="post-metadata">

**Author:** ![saxosurfin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@saxosurfin](https://www.ruby-forum.com/u/saxosurfin)\
**Post date:** [October 12, 2009, 5:31pm UTC](https://www.ruby-forum.com/t/processing-an-xml-list-in-a-controller/176785/5 "2009-10-12T17:31:02Z")

</div>

Hi

thnkas for the responses, I have tried to prgress this by using REXML,  
and I have tried creating an REXL doc using

doc = REXML::Document.new ranking

where ranking is a variable that I have assigned from the paramters  
submitted to my controller, the parameters shown in the log as  
follows:

Parameters: {“ranking”=\>{“asset”=\>[{“title”=\>“title one”, “id”=\>“1”,  
“rank”=\>“1”},  
{“title”=\>“title two”, “id”=\>“2”, “rank”=\>“2”},  
{“title”=\>"title fourteen ", “id”=\>“14”, “rank”=\>“3”},

```
       .......
         {"title"=>"title xxxxx", "id"=>"3", "rank"=>"12"},
         {"title"=>"title yyyyyy", "id"=>"10", "rank"=>"13"}]},
         "_method"=>"put", "action"=>"ranking", "path_prefix"=>"/

```

demo", “controller”=\>“assets”}

As a result of the Document.new I get the following error

NameError (undefined local variable or method `source' for REXML::SourceFactory:Class): c:/ruby/lib/ruby/1.8/rexml/source.rb:20:in`create\_from’  
c:/ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:130:in `stream=' c:/ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:107:in`initialize’  
c:/ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in `new' c:/ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in`initialize’

I have tried various options but can’t seem to get round this. I  
assume I am having this problem as REXML does not recoginise the input  
to the new constructor as XML.

If anyone can shed any light on this I would much appreciate it.

cheers, G
