我刚刚开始使用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