0

我已使用此命令将 xml 文件发送到名为 SRA-ENA 的 Web 服务。

 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 格式的收据,

请有人指导我如何将这个 xml 保存在一个变量中,以便我可以使用 nokogiri 进一步解析 xml 文件。

4

1 回答 1

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
于 2012-02-08T14:55:51.543 回答