views:

495

answers:

2

Hi!

I've just started using HTTParty, and i've encountered a problem in the way it builds the Hash from the XML replied by the server.

If i setup the following Builder template on the server:

xml.thunt :sendSubscriptionResult, :"xmlns:thunt" => "http://example.com/thunt", :status => @status

everything works well, i.e. the Hash built by HTTParty matches the XML generated by Builder, (the latter can be observed by making the same request via curl):

curl Request

curl -s -H "Accept: text/xml" -d "xml=`cat vendor/testxml/requests/sendsubscription.xml`" $SERVER/${name}

Reply as seen by curl

    '<thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed" />'

HTTParty request

TreasureHunt.post('/sendsubscription', :query => { :xml => sub } )

Reply in HTTParty

{"thunt:sendSubscriptionResult"=>{"status"=>"alreadySubscribed", "xmlns:thunt"=>"http://example.com/thunt"}}


But, if in the Builder i specify that i want the sendSubscriptionResult element to have a text node:

xml.thunt :sendSubscriptionResult, "Hello, World", :"xmlns:thunt" => "http://example.com/thunt", :status => @status

(note the "Hello, World" addition) the two tools suddenly disagree.

curl

'<thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed">Hello, World</thunt:sendSubscriptionResult>'

HTTParty

{"thunt:sendSubscriptionResult"=>"Hello, World"}

As you can see, HTTParty has stripped all of the element's attributes, and has put only the text node in the resulting Hash

Is this a bug in HTTParty or am I doing something wrong? Thanks!

A: 

I would go ahead and post your problems on the issues page for their Github project.

http://github.com/jnunemaker/httparty/issues

It already looks like there are some issues surrounding some XML issues. But it's definitely the best way to communicate directly with the developers and to provide them feedback.

mwilliams
thanks, it seems i'm not the only one who noticed this bug!
asymmetric
+1  A: 

Check out my post on the github issue for a resolution to your problem. http://github.com/jnunemaker/httparty/issues/#issue/14

Ed Schmalzle
thanks a lot! the xml_test.rb file was a useful read!
asymmetric
i should add that i see no reason why it should be so complicated and unnecessarily cluttered to get a coherent hash out of the xml..
asymmetric