Parsing XML to hash with Nori and Nokogiri with undesired result

Ronsta

New Member
I am attempting to convert an XML document to a Ruby hash using Nori. But instead of receiving a collection of the root element, a new node containing the collection is returned. This is what I am doing:\[code\]@xml = content_for(:layout)@hash = Nori.new(:parser => :nokogiri, :advanced_typecasting => false).parse(@xml)\[/code\]or\[code\]@hash = Hash.from_xml(@xml)\[/code\]Where the content of \[code\]@xml\[/code\] is:\[code\]<bundles> <bundle> <id>6073</id> <name>Bundle-1</name> <status>1</status> <bundle_type> <id>6713</id> <name>BundleType-1</name> </bundle_type> <begin_at nil=\"true\"></begin_at> <end_at nil=\"true\"></end_at> <updated_at>2013-03-21T23:02:32Z</updated_at> <created_at>2013-03-21T23:02:32Z</created_at> </bundle> <bundle> <id>6074</id> <name>Bundle-2</name> <status>1</status> <bundle_type> <id>6714</id> <name>BundleType-2</name> </bundle_type> <begin_at nil=\"true\"></begin_at> <end_at nil=\"true\"></end_at> <updated_at>2013-03-21T23:02:32Z</updated_at> <created_at>2013-03-21T23:02:32Z</created_at> </bundle></bundles>\[/code\]The parser returns \[code\]@hash\[/code\] of format:\[code\]{"bundles"=>{"bundle"=>[{"id"=>"6073", "name"=>"Bundle-1", "status"=>"1", "bundle_type"=>{"id"=>"6713", "name"=>"BundleType-1"}, "begin_at"=>nil, "end_at"=>nil, "updated_at"=>"2013-03-21T23:02:32Z", "created_at"=>"2013-03-21T23:02:32Z"}, {"id"=>"6074", "name"=>"Bundle-2", "status"=>"1", "bundle_type"=>{"id"=>"6714", "name"=>"BundleType-2"}, "begin_at"=>nil, "end_at"=>nil, "updated_at"=>"2013-03-21T23:02:32Z", "created_at"=>"2013-03-21T23:02:32Z"}]}} \[/code\]Instead I would like to get:\[code\]{"bundles"=>[{"id"=>"6073", "name"=>"Bundle-1", "status"=>"1", "bundle_type"=>{"id"=>"6713", "name"=>"BundleType-1"}, "begin_at"=>nil, "end_at"=>nil, "updated_at"=>"2013-03-21T23:02:32Z", "created_at"=>"2013-03-21T23:02:32Z"}, {"id"=>"6074", "name"=>"Bundle-2", "status"=>"1", "bundle_type"=>{"id"=>"6714", "name"=>"BundleType-2"}, "begin_at"=>nil, "end_at"=>nil, "updated_at"=>"2013-03-21T23:02:32Z", "created_at"=>"2013-03-21T23:02:32Z"}]}\[/code\]Is there an option that I am missing?
 
Back
Top