我和萨文打了一个肥皂电话.这工作正常,并给予
以下回复:
以下回复:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http:// schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetTop10Response xmlns="http://www.kirupafx.com"> <GetTop10Result> <string>string</string> <string>string</string> </GetTop10Result> </GetTop10Response> </soap:Body> </soap:Envelope>
现在我想从响应中取出所有字符串元素.但
我无法让它发挥作用.
def query(params=nil) client = Savon::Client.new do wsdl.document = "http://www.kirupafx.com/WebService/TopMovies.asmx?wsdl" end response = client.request :get_top10 if response.success? xml = Nokogiri::XML(response.to_xml) print "Until here oké!" xml.search('//GetTop10Result').each do |result| print "How are you Ruby?" @result[result.at('string').inner_text] = result.at('string').inner_text end else raise "Error!" end
但是他从来没有打印过我漂亮的“你是红宝石怎么样?”有人可以帮忙吗?
我?我做错了什么?
解决方法
你可以这样,但这不是处理这样的问题的最好方法!您可能有使用Nokogiri和XML的经验,但它更容易使用.to_hash这样.
def query client = Savon::Client.new do wsdl.document = "http://www.kirupafx.com/WebService/TopMovies.asmx?wsdl" end response = client.request(:get_top10) response.to_hash[:get_top10_response][:get_top10_result] if response.success? false end