2009-07-02 67 views
1

我刚刚开始使用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中的错误还是我做错了什么? 谢谢!

+0

我已经没有什么,但XML和HTTParty的麻烦,所以我很想看到这一个坚实的答案。 – tadman 2009-07-03 19:23:34

回答

0

我会继续,并在问题页面上发布您的问题,为他们的Github项目。

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

它已经看起来像有周边的一些XML问题的一些问题。但它绝对是与开发人员直接沟通并向他们提供反馈的最佳方式。

+0

谢谢,看来我不是唯一一个注意到这个bug的人! – asymmetric 2009-07-05 10:42:36

0

在底层,httparty目前使用multi_xml进行XML解析。 multi_xml将使用基于可用解析gem的速度:Ox,LibXML,Nokogiri,REXML。也就是说,如果你安装了它,它会首先选择Ox。您也可以指定使用哪个解析器。

最近在multi_xml中解决了一些错误,特别是在数组方面。

我建议你点打捆到GitHub库,以获得最新的版本multi_xml的,在你的Gemfile这样的:

gem 'multi_xml', :git => 'https://github.com/sferik/multi_xml' 
gem 'ox' 
gem 'httparty' 

然后,你要使用httparty(例如,在你的西纳特拉服务器),你可以这样做:

require 'bundler/setup' 

请注意,这个设置,multi_xml就不会在“宝石列表”输出上显示,但它会奏效。