0

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 )

In response to this, I receive a receipt from the web server in xml format,

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.

Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123
A1aks
  • 187
  • 1
  • 2
  • 15

1 Answers1

0

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
Don Cruickshank
  • 5,641
  • 6
  • 48
  • 48
  • Don, Please could you tell me how do you know whether the data sent via curb is the right one. I have followed your method above and I get an HTTP 415 Error. Is there any way of finding/testing Curb results. – A1aks Feb 08 '12 at 17:25
  • Unfortunately, a 415 response means that the server didn't like the data that you gave it. There's no way of knowing why without reading up on the particular web service or contacting the people that run it. – Don Cruickshank Feb 08 '12 at 22:45
  • Dear Don, Please could you refer this http://stackoverflow.com/questions/9227028/retrieving-xml-from-third-part-web-service and suggest if I am on the right track in coding – A1aks Feb 10 '12 at 11:24
  • Hi Don, Sorry if I am asking you a simple question. Please could you kindly tell me how do I call the attribute doc in the view template when I want to display the right xml element object.! Thanks – A1aks Feb 11 '12 at 11:05