我刚刚开始使用HTTParty,在从服务器回复的XML构建哈希的方式上遇到了一个问题。
如果我在服务器上设置了以下Builder模板:
xml.thunt :sendSubscriptionResult, :"xmlns:thunt" => "http://example.com/thunt", :status => @status所有操作都很好,即由HTTParty构建的哈希与Builder生成的XML匹配(后者可以通过curl发出相同的请求来观察):
卷曲请求
curl -s -H "Accept: text/xml" -d "xml=`cat vendor/testxml/requests/sendsubscription.xml`" $SERVER/${name}回复如curl所见
'<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"}}但是,如果在生成器中我指定希望sendSubscriptionResult元素有一个文本节点:
xml.thunt :sendSubscriptionResult, "Hello, World", :"xmlns:thunt" => "http://example.com/thunt", :status => @status(注意"Hello,World“的添加)这两个工具突然不一致了。
curl
'<thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed">Hello, World</thunt:sendSubscriptionResult>'HTTParty
{"thunt:sendSubscriptionResult"=>"Hello, World"}如您所见,HTTParty已经删除了元素的所有属性,并且只将文本节点放置在生成的哈希中
这是HTTParty中的一个bug,还是我做错了什么?谢谢!
发布于 2009-07-07 02:45:41
查看我在github问题上的帖子,以解决您的问题。http://github.com/jnunemaker/httparty/issues/#issue/14
发布于 2009-07-05 03:59:19
我会继续,并将您的问题张贴在问题页为他们的Github项目。
http://github.com/jnunemaker/httparty/issues
看起来,围绕一些XML问题已经存在一些问题。但这绝对是直接与开发人员沟通并提供反馈的最佳方式。
发布于 2012-02-01 05:40:08
在幕后,httparty目前使用multi_xml进行XML解析。multi_xml将根据可用解析gem的速度使用: Ox、LibXML、Nokogiri、REXML。也就是说,如果您安装了Ox,它将首先选择Ox。您还可以指定使用哪个解析器。
最近在multi_xml中解决了一些bug,特别是在数组方面。
我建议您将邦德勒指向GitHub回购系统,以便在Gemfile中获得最新版本的multi_xml,如下所示:
gem 'multi_xml', :git => 'https://github.com/sferik/multi_xml'
gem 'ox'
gem 'httparty'然后,在要使用httparty的地方(例如,在Sinatra服务器中),您可以这样做:
require 'bundler/setup'请注意,使用此设置,multi_xml将不会出现在您的“宝石列表”输出中,但它将工作。
https://stackoverflow.com/questions/1075966
复制相似问题