我剛剛開始使用HTTParty,並且在從服務器回覆的XML中構建哈希的方式中遇到了問題。XML和HTTParty問題
如果我安裝在服務器上的以下工具模板:
xml.thunt :sendSubscriptionResult, :"xmlns:thunt" => "http://example.com/thunt", :status => @status
一切正常,即由HTTParty建哈希通過生成器生成的XML,(後者可以通過使同樣的請求,可以觀察到匹配通過捲曲):
捲曲請求
curl -s -H "Accept: text/xml" -d "xml=`cat vendor/testxml/requests/sendsubscription.xml`" $SERVER/${name}
REPL ÿ如由捲曲
'<thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed" />'
HTTParty請求
TreasureHunt.post('/sendsubscription', :query => { :xml => sub })
回覆在HTTParty
{"thunt:sendSubscriptionResult"=>{"status"=>"alreadySubscribed", "xmlns:thunt"=>"http://example.com/thunt"}}
但是看出,如果在Builder我指定我想要的sendSubscriptionResult元素有一個文本節點:
xml.thunt :sendSubscriptionResult, "Hello, World", :"xmlns:thunt" => "http://example.com/thunt", :status => @status
(注意是「你好,世界」加法)這兩個工具突然不同意。
捲曲
'<thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed">Hello, World</thunt:sendSubscriptionResult>'
HTTParty
{"thunt:sendSubscriptionResult"=>"Hello, World"}
正如你所看到的,HTTParty已全部剝離元素的屬性,並已投入只有文本節點中所產生的哈希
這是HTTParty中的錯誤還是我做錯了什麼? 謝謝!
我已經沒有什麼,但XML和HTTParty的麻煩,所以我很想看到這一個堅實的答案。 – tadman 2009-07-03 19:23:34