Вот пример контроллера, который я выбил для проверки парсинга xml
Я могу использовать метод get_names в представлении, чтобы получить массив имен
require 'rho/rhocontroller'
require 'rexml/document'
class WebServiceTestController < Rho::RhoController
def index
@@get_result = ""
Rho::AsyncHttp.get(
:url => 'http://www.somesite.com/some_names.xml',
#:authorization => {:type => :basic, :username => 'user', :password => 'none'},
:callback => (url_for :action => :httpget_callback),
:authentication => {
:type => :basic,
:username => "xxxx",
:password => "xxxx"
},
:callback_param => "" )
render :action => :wait
end
def get_res
@@get_result
end
def get_error
@@error_params
end
def httpget_callback
if @params["status"] != "ok"
@@error_params = @params
WebView.navigate( url_for(:action => :show_error) )
else
@@get_result = @params["body"]
begin
# require "rexml/document"
@@doc = REXML::Document.new(@@get_result)
# puts "doc : #{doc}"
rescue Exception => e
# puts "Error: #{e}"
@@get_result = "Error: #{e}"
end
WebView.navigate( url_for(:action => :show_result) )
end
end
def show_error
render :action => :error, :back => '/app'
end
def show_result
render :action => :index, :back => "/app"
end
def get_doc
@@doc
end
def get_names
names = []
REXML::XPath.each( get_doc, "//name_or_whatever_you_are_looking_for") do |element|
names << element.text
end
names
end
end
убедитесь, что rhoxml установлен в файле build.yml, а не rexml, это отлично работает и работает немного быстрее