2012-02-08 38 views
0

我已經使用此命令將XML文件發送到名爲SRA-ENA的Web服務。收集第三方Web服務的xml響應

submission_field = Curl::PostField.content(File.read("xml/#{@experiment.alias}.submission.xml"), 'SUBMISSION') 
     study_field = Curl::PostField.content(File.read("xml/#{@experiment.alias}.study.xml"), 'STUDY') 
     sample_field = Curl::PostField.content(File.read("xml/#{@experiment.alias}.sample.xml"), 'SAMPLE') 
     run_field = Curl::PostField.content(File.read("xml/#{@experiment.alias}.run.xml"), 'RUN') 
     experiment_field = Curl::PostField.content(File.read("xml/#{@experiment.alias}.experiment.xml"), 'EXPERIMENT') 
     # Send these requests to the test-SRA website 
     request_test = Curl::Easy.http_post("https://www-test.ebi.ac.uk/ena/submit/drop-box/submit/?auth=ERA%20era-drop-81%20dxjf2dntWDr4CHg28qERORnv0RQ%3D", submission_field, study_field, sample_field, run_field, experiment_field) 

在回答這個問題,我收到一張收據從XML格式的Web服務器,

請可有人指導我如何保存這個XML的變量,這樣我可以使用引入nokogiri進一步解析xml文件。

回答

0

這是一個獨立的例子,使用Rails 2.3.14,展示瞭如何使用nokogiri來解析XML結果。

require 'nokogiri' 
require 'curb' 

# I have included this part so that this serves as a standalone example 

ce = Curl::Easy.new("http://www.myexperiment.org/announcements.xml") 
ce.perform 

# This is the part that deals with parsing the XML result using nokogiri 

doc = Nokogiri::XML::Document.parse(ce.body_str) 

doc.xpath("/announcements/announcement").each do |announcement| 
    puts announcement.content 
end 
+0

唐, 請你能告訴我你怎麼知道通過路邊發送的數據是否是正確的。我已經按照上面的方法,並且得到了HTTP 415錯誤。有沒有找到/測試Curb結果的方法。 – A1aks 2012-02-08 17:25:02

+0

不幸的是,415響應意味着服務器不喜歡你給它的數據。沒有辦法知道爲什麼不閱讀特定的Web服務或聯繫運行它的人。 – 2012-02-08 22:45:56

+0

親愛的唐,請你可以參考這個http://stackoverflow.com/questions/9227028/retrieving-xml-from-third-part-web-service 並建議如果我在編碼的正確軌道 – A1aks 2012-02-10 11:24:58