通过第三方Web服务收集xml响应 [英] Collect xml response by third party web service
本文介绍了通过第三方Web服务收集xml响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已使用此命令将xml文件发送到名为SRA-ENA的Web服务.
I have used this command to send xml files to a web service named SRA-ENA.
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 )
对此,我从Web服务器收到xml格式的收据,
In response to this, I receive a receipt from the web server in xml format,
请有人指导我如何将xml保存到变量中,以便我可以使用nokogiri进一步解析xml文件.
Please could some one guide me how to save this xml in a variable so that I can use nokogiri to further parse the xml file.
推荐答案
下面是一个使用Rails 2.3.14的独立示例,该示例显示了如何使用nokogiri解析XML结果.
Here is a standalone example, using Rails 2.3.14, that shows how to use nokogiri to parse XML results.
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
这篇关于通过第三方Web服务收集xml响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文