Processing an XML list in a controller

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.

suggesting gem nokogiri too

Sijo

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

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

–Matt

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:increate_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:ininitialize’
c:/ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in new' c:/ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:ininitialize’

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