私はHTTPartyを使い始めました。サーバーから返されたXMLからHashを構築する方法に問題が発生しました。XMLとHTTPartyの問題
私のセットアップサーバー上で次のビルダーのテンプレート場合:
xml.thunt :sendSubscriptionResult, :"xmlns:thunt" => "http://example.com/thunt", :status => @status
をHTTPartyによって建設されたハッシュは、Builderで生成されたXMLに一致する。すなわち、すべてが、うまく機能し、(後者は同じ要求を行うことによって観察することができます経由カール):
カール・リクエスト
curl -s -H "Accept: text/xml" -d "xml=`cat vendor/testxml/requests/sendsubscription.xml`" $SERVER/${name}
REPL Y HTTParty
{"thunt:sendSubscriptionResult"=>{"status"=>"alreadySubscribed", "xmlns:thunt"=>"http://example.com/thunt"}}
しかしに
'<thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed" />'
カール
HTTParty要求
TreasureHunt.post('/sendsubscription', :query => { :xml => sub })
返信によって見られるように、
xml.thunt :sendSubscriptionResult, "Hello, World", :"xmlns:thunt" => "http://example.com/thunt", :status => @status
(「こんにちは、世界」ほかの点に注意してください。)2つのツールが突然反対する:Builderで私は私がしたいことを指定した場合sendSubscriptionResult要素は、テキストノードを持っています。
カール
'<thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed">Hello, World</thunt:sendSubscriptionResult>'
HTTParty
{"thunt:sendSubscriptionResult"=>"Hello, World"}
あなたが見ることができるように、HTTPartyは、要素の属性をすべて取り除いた、そして得られたハッシュでのみテキストノードを入れている
これはHTTPartyのバグですか?何か間違っていますか? ありがとう!
XMLとHTTPartyには何の問題もありませんでしたので、私はこれに確かな答えを見たいと思っています。 – tadman