# Parse XML post as parameters hash

**URL:** <https://www.ruby-forum.com/t/parse-xml-post-as-parameters-hash/193330>\
**Category:** Rails\
**Created:** [August 16, 2010, 6:32am UTC](https://www.ruby-forum.com/t/parse-xml-post-as-parameters-hash/193330 "2010-08-16T06:32:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![markb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@markb](https://www.ruby-forum.com/u/markb)\
**Post date:** [August 16, 2010, 6:32am UTC](https://www.ruby-forum.com/t/parse-xml-post-as-parameters-hash/193330/1 "2010-08-16T06:32:59Z")

</div>

I am trying to add a controller method that will take an XML post with  
a schema not related to an existing model and parse it as a hash of  
parameters. I create apis\_controller.rb:

class ApisController \< ApplicationController  
def create  
puts “\*\*\*\* API INVOKED \*\*\*\*”  
puts params[:name]  
end  
end

Then…

curl --data-urlencode “Foo” -H “Content-Type:application/  
xml” [http://localhost:3000/apis.xml](http://localhost:3000/apis.xml)

I get the following error:

Status: 500 Internal Server Error  
undefined method `name’ for nil:NilClass

Is there a way for “puts params[:name]” to display “Foo” upon  
receiving the XML post?

Thanks in advance!  
Mark

---

<div class="post-metadata">

**Author:** ![markb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@markb](https://www.ruby-forum.com/u/markb)\
**Post date:** [August 16, 2010, 8:42am UTC](https://www.ruby-forum.com/t/parse-xml-post-as-parameters-hash/193330/2 "2010-08-16T08:42:20Z")

</div>

Hello,

Your parameters are not seen as xml content.

You should put your xml content on a file an send it with : curl -d  
@file\_to\_send …

In this case you will automatically get your xml as a map on the params  
map.

Mickael

---

<div class="post-metadata">

**Author:** ![markb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@markb](https://www.ruby-forum.com/u/markb)\
**Post date:** [August 17, 2010, 7:25am UTC](https://www.ruby-forum.com/t/parse-xml-post-as-parameters-hash/193330/3 "2010-08-17T07:25:16Z")

</div>

Thank you so much, Mickael. This is indeed what I was missing. Much  
appreciated.

Mark
